iphone - how to implement two different animations on same sprite in cocos2d -


i'm confused on using animations in cocos2d... i've sprite has 3 types of animations, smiley laughs, cries , winks eyes... , have separate sprite sheets each of these animations... how able use these animations on same sprite... can me please???

regards,

suraj

it easier have animations on same sprite sheet, as, if sprite using ccbatchnode it's draw method, you'd have remove child 1 sheet, , readd another.

in ccsprite subclass, set ccaction's instance variables.

in initialization method, write actions , store them instance variables.

then when want use animation, tell sprite run it.

e.g.

nsmutablearray *smileframes = [nsmutablearray array]; [smileframes addobject:[[ccspriteframecache sharedspriteframecache] spriteframebyname:@"character_smile.png"]]; [smileframes addobject:[[ccspriteframecache sharedspriteframecache] spriteframebyname:@"character_smile2.png"]]; [smileframes addobject:[[ccspriteframecache sharedspriteframecache] spriteframebyname:@"character_smile3.png"]];   ccanimation *smileanim = [ccanimation                           animationwithframes:smileframes delay:0.2f];  self.smileaction = [ccsequence actions:                    [ccanimate actionwithanimation:smileanim restoreoriginalframe:no],                    [cccallfunc actionwithtarget:self selector:@selector(smilefinished)],                    nil]; 

then use..

[sprite runaction:smileaction]; 

i have added cccallfunc end of animation, may want revert idle animation after finished.

don't forget release retained actions when sprite deallocated.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -