2012-01-07 157 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