cocos2d sprite repeat animation forever

≡放荡痞女 提交于 2019-11-28 11:48:38
Kirit Modi

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!