精灵的时间延迟,cocos2d

发布于 2024-12-25 07:25:28 字数 1397 浏览 1 评论 0原文

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

这里是精灵的代码(如果有帮助的话)

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

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

i want to add a delay to a sprite so when i enter a new scene it doesnt play straight away, any advice would be greatful thanks

heres the code of the sprite if it helps

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如痴如狂 2025-01-01 07:25:28

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

[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];
}

create a new method for adding new sprite and call this after delay:

[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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文