【问题标题】:time delay for sprite, cocos2d精灵的时间延迟,cocos2d
【发布时间】:2012-02-04 19:46:18
【问题描述】:

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

如果有帮助,这里是精灵的代码

//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];

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

【问题讨论】:

  • 尝试搜索NSTimer。我确信有一些关于使用它的教程。

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


【解决方案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];
}

【讨论】:

  • 感谢您的帮助,我对其进行了排序,但它不允许我发布答案。它是否与我的建议非常相似。感谢您的宝贵时间,非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 2012-09-21
  • 1970-01-01
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多