Cocos2d hide / show sprites with animation

I spend a lot on my time for the simple things that I think about. I want to hide and show the sprite in the scene.

myS = [CCSprite spriteWithFile:@"Background_Pause_pad.png"]; [myS setPosition:ccp(384,470)]; myS.opacity = 0; [self addChild:myS z:1]; 

and when I need to display it ..

 [myS runAction:[CCFadeIn actionWithDuration:1]]; 

and hide it

 [myS runAction:[CCFadeOut actionWithDuration:1]]; 

but it doesn’t work ..... can anyone help plz?

+4
source share
2 answers
  • Why are you using a sequence for one action?
  • You need to select the desired animation!
  • For example: if you select CCFadeIn
 [mySprite runAction:[CCFadeIn actionWithDuration:0.5f]]; 
+5
source

I think you can try the following code things. This will work for you.

 id action1 = [CCFadeIn actionWithDuration:1]; id action2 = [CCDelayTime actionWithDuration:1]; id action3 = [CCFadeOut actionWithDuration:1]; [myS runAction:[CCSequence actions:action1,action2,action3,nil]]; 

As you need the fadein fadeout action, it will generate it and display Same.

+2
source

All Articles