2 for 2012 for_2012 于 2013.03.20 14:30 提问

cocos2D中的应用动画延迟

代码:

if (CGRectIntersectsRect(food.sprite.boundingBox, playerRect)) {
    [food.sprite stopAllActions]; 

    [walkAnimFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:

    [NSString stringWithFormat:@"newpackman2.png", 0]]];

    [walkAnimFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:

    [NSString stringWithFormat:@"newpackman3.png", 1]]];

    walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.2f];

    self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];

    self.walkAction.tag = 1;
    [chef runAction:_walkAction];
}

这段代码可以正常运行,在固定时间会触发动画。

但是我需要动画在3-4秒的延迟之后开始。

我用过 [sprite stopActionByTag:1] 没有实现。请高手帮忙,谢谢

2个回答

love_loveec
love_loveec   2013.03.20 15:24
已采纳

你可以创建一个动作block来实现延迟,调用stopAllActions:

CCSprite *sprite = ...;

CCCallBlock *block = [CCCallBlock actionWithBlock:^{
            [sprite stopAllActions];
        }];

然后使用CCDelayTime:

CCDelayTime *time = [CCDelayTime actionWithDuration:4];


[sprite runAction:[CCSequence actions:time, block, nil]];
xinyoulingxi1_tong
xinyoulingxi1_tong   2013.03.20 16:03

试试

CCDelayTime *time = [CCDelayTime actionWithDuration:10];// After 10 mile seconds

[sprite runAction:[CCSequence actions:time, block, nil]];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!