Cocos2D Sprite Repeat Animation Forever

cocos2d sprite repeat animation forever

First of all you download Texture from 'http://www.codeandweb.com/texturepacker/download'
and make p-List and use it below code

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimatedMan.plist"];

CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"AnimatedMan.png"];

[self addChild:spriteSheet];

Gather the list of frames(sprite)

NSMutableArray *walkAnimFrames = [NSMutableArray array];
for (int i=1; i<=6; i++) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"step0%d.png",i]]];
}

give the Action to the Sprite

CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.1f];

manSprite=[CCSprite spriteWithSpriteFrameName:@"step01.png"];
manSprite.position=ccp(winsize.width/2, winsize.height/2-40);

Sprite RepeaetForever for manSprite

id first=[CCSequence actions:[CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim]],nil];

[manSprite runAction:first];

Cocos2d fade in/out action to repeat forever

I have not run this, but I think others have succeeded with something like:

- (void)pulse
{
[self setOpacity:1.0];
CCFadeTo *fadeIn = [CCFadeTo actionWithDuration:0.5 opacity:127];
CCFadeTo *fadeOut = [CCFadeTo actionWithDuration:0.5 opacity:255];

CCSequence *pulseSequence = [CCSequence actionOne:fadeIn two:fadeOut];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:pulseSequence];
[self runAction:repeat];
}

Repeating Background in Cocos2D 2.0 turns sprite black

I struggled with getting a single background image to scroll how I wanted it to for a while. I found this, which is very easy to implement and works well. Just copy the files into the cocos2d folder on your project, and follow the short tutorial shown in the link, and everything should work well.

How to properly setup a Cocos2D Animation Sequence with repeating animations

I don't know if there is a recommended approach. What I would do is running the second animation (the repeating one) with a delay or by chaining it to the first through the animation completion handler.

An easy way to do the chaining is adding at the end of your first animation a CCCallFunc action, like here, that will call trigger the second animation:

CCActionInterval* action = [CCSequence actions:
[CCProgressFromTo actionWithDuration:duration_ from:100.f to:0.f],
[CCCallFunc actionWithTarget:self selector:@selector(startSecondAction)],
nil ];


Related Topics



Leave a reply



Submit