cocos2d sprite repeat animation forever

前端 未结 1 762
礼貌的吻别
礼貌的吻别 2020-12-10 23:06

In my iOS game, I hope the hero keep running until screen is touched and the hero should jump. So I write:
In .h file:

@interface Hero : CCSprite {
          


        
相关标签:
1条回答
  • 2020-12-10 23:29

    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];
    
    0 讨论(0)
提交回复
热议问题