精灵的时间延迟,cocos2d

时间:2012-01-07 09:35:12

标签: iphone cocos2d-iphone sprite sprite-sheet timedelay

我想为精灵添加一个延迟,所以当我进入一个新场景它不会立即播放时,任何建议都会非常感谢

如果有帮助的话,那就是精灵的代码

//SPRITES BIRD ONE -------------------------
    //------------------------------------------
    CCSpriteFrameCache *cache=[CCSpriteFrameCache sharedSpriteFrameCache];
    [cache addSpriteFramesWithFile:@"house-ipad.plist"];

    // frame array
    NSMutableArray *framesArray=[NSMutableArray array];
    for (int i=1; i<24; i++) {
        NSString *frameName=[NSString stringWithFormat:@"house-ipad%d.png", i];
        id frameObject=[cache spriteFrameByName:frameName];
        [framesArray addObject:frameObject];
    }

    // animation object
    id animObject=[CCAnimation animationWithFrames:framesArray delay:0.035];

    // animation action;
   id animAction=[CCAnimate actionWithAnimation:animObject restoreOriginalFrame:NO];
    //id animAction=[CCAnimate actionWithDuration:4 animation:animObject restoreOriginalFrame:NO];
    //animAction=[CCRepeatForever actionWithAction:animAction];

    // sprite (width,height)
    CCSprite *bird=[CCSprite spriteWithSpriteFrameName:@"house-ipad1.png"];

    bird.position=ccp(550,470);


    // batchNode
    CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"house-ipad.png"];
    [self addChild:batchNode];
    [batchNode addChild:bird];

    [bird runAction:animAction];

    //-----------------------------------------

1 个答案:

答案 0 :(得分:1)

创建一个添加新精灵的新方法,并在延迟后调用它:

[self performSelector:@selector(afterDelay:) withObject:animAction afterDelay:0.5];

-(void)afterDelay:(id)animAction
{
// sprite (width,height)
 CCSprite *bird=[CCSprite spriteWithSpriteFrameName:@"house-ipad1.png"];

bird.position=ccp(550,470);


// batchNode
CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"house-ipad.png"];
[self addChild:batchNode];
[batchNode addChild:bird];

[bird runAction:animAction];
}