2012-01-07 121 views
0

我想延迟添加到一个精灵,所以当我进入一个新的场景它不打直线距离,任何建议将不胜感激感谢时间延迟,cocos2d的

继承人的精灵的代码,如果有帮助

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

    //----------------------------------------- 
+0

尝试搜索'NSTimer'。我确定有一些关于使用它的教程。 – evotopid 2012-01-07 09:37:20

回答

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]; 
} 
+1

感谢您的帮助,我整理了它,但它不会让我发布答案。它与我所建议的非常相似吗?非常感谢您的时间 – 2012-01-07 13:55:14