首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >sprite、cocos2d的时间延迟

sprite、cocos2d的时间延迟
EN

Stack Overflow用户
提问于 2012-01-07 17:35:12
回答 1查看 1.3K关注 0票数 0

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

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

代码语言:javascript
运行
复制
//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];

    //-----------------------------------------
EN

回答 1

Stack Overflow用户

发布于 2012-01-07 18:18:22

创建一个用于添加新sprite的新方法,并在delay之后调用此方法:

代码语言:javascript
运行
复制
[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];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8768700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档