Reputation: 253
Why the created name of a sprite isn't saved or even returned ?
I add several objects (SKSpriteNode) in the init of the Scene
-(id)initWithSize:(CGSize)size {
NSArray *oxyObjects = [self.oxygens objectsNamed:@"oxy"];
for (NSDictionary *enemyObj in oxyObjects) {
SKSpriteNode *oxyNode = [SKSpriteNode spriteNodeWithImageNamed:@"oxygen"];
NSString *valeurX=enemyObj[@"x"];
float x = [valeurX floatValue];
NSString *valeurY=enemyObj[@"y"];
float y = [valeurY floatValue];
CGPoint oxyPosition = CGPointMake(x, y);
oxyNode.position = oxyPosition;
oxyNode.name = @"ballOxygen";
NSLog(@"oxy %@",oxyNode);
[self.map addChild:oxyNode];
}
The log give me this with the correct name for the sprite
oxy name:'ballOxygen' texture:[ '[email protected]' (24 x 24)] position:{454, 99} size:{12, 12} rotation:0.00
To check collision, I tried to use
[[self children] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
SKNode *node = (SKNode *)obj;
NSLog(@"obj : %@", obj);
Or this
NSArray *nodes = self.children;
for(SKNode * node in nodes){
SKSpriteNode *obj = (SKSpriteNode *) node;
NSLog(@"obj : %@", obj);
But It return always a null name
obj : name:'(null)' texture:[ '[email protected]' (8 x 24)] position:{100, 100} size:{17, 12} rotation:0.00
Upvotes: 0
Views: 347
Reputation: 64477
My best guess:
You are adding oxyNode to self.map but you are enumerating self.children where you probably should be enumerating self.map.children.
Try this:
[self.map.children enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
SKNode *node = (SKNode *)obj;
NSLog(@"obj : %@ (%p)", obj, obj);
}];
Upvotes: 1