用SpriteBuilder简化"耕牛遍地走"的动画效果(三)

接下来的代码和原文差不多,建立一个数组用来存放动画帧,然后用数组来初始化一个CCAnimation动画对象.接着将牛放在屏幕中心,然后运行动画:

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

    CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames
                                                             delay:0.1f];
    CGSize viewSize = [CCDirector sharedDirector].viewSize;
    _bear = [CCSprite spriteWithImageNamed:@"BearImagesHD/bear1.png"];
    _bear.position = ccp(viewSize.width/2,viewSize.height/2);
    CCActionAnimate *animate = [CCActionAnimate actionWithAnimation:walkAnim];
    _walkAction = [CCActionRepeatForever actionWithAction:animate];
    [_bear runAction:_walkAction];
    [sheet addChild:_bear];

如果切正常,你将看到一头原地溜达的耕牛:

用SpriteBuilder简化"耕牛遍地走"的动画效果(三)_第1张图片

这还不是指哪走哪的牛牛,不是我们所要的耕牛遍地走的状态,下一篇我们再来完善 ;)

你可能感兴趣的:(动画,cocos2d,builder,Sprite)