So in my project, I call an instance method called “-(void)fire” in the class “Survival.m”:
-(void)fire {
NSLog(@"Firing");
CCSprite *sprite = [CCSprite spriteWithFile:@"bullet.png"];
sprite.position = player.position;
NSLog(@"%@",NSStringFromCGPoint(player.position));
[self addChild:sprite z:100];
}
When I do this, the sprite doesn’t show on the screen.
The method is being called from another layer but since it logs “Firing” every time I tap the button, it’s not the problem.
I am using a TMXTiledMap as well if that could cause any problems.
Please help, thanks!
EDIT———
I can create sprites in the other layer, HUDLayer but not in the Survival layer which contains the player and the tiled map. If I create a sprite in the “init” method, it works correctly but If i do it in the method “fire” it doesn’t work. The method “fire” is being called from the HUDLayer but I still now the method is being called since I see in the log that it says “Firing”
Could it be that:
1. The sprite is being created out of sight?
2. The sprite is not being created?
3. The sprite is not added to the correct parent?
Any suggestions?
Thanks Everybody, Solved it in some mysterious way. Thanks for the help anyway. I think I declared the layer in a wrong way.
Have a nice day!