2014-02-22 100 views
0

我該如何推遲'計劃',然後不計劃。因此,計劃中有一個延遲,它會重新計劃並將間隔更改爲較小的增量?非計劃和重新計劃Cocos2d 3.0

此代碼

- (void)onEnter 
{ 
[super onEnter]; 

[self schedule:@selector(addMonster:) interval:1.0]; 
[self schedule:@selector(addBomb:) interval:4.0]; 
[self schedule:@selector(addLife:) interval:45.0]; 

} 
+1

你是什麼意思,推遲日程安排?你正在尋找一種方法來減少怪物的時間間隔嗎? –

+0

是的,但在某個時間 – Crazycriss

回答

0

在你的init

[self scheduleUpdate]; 

在更新調用不同的選擇,當時間條件滿足。爲了創建時間條件,我們將需要一些全局變量。

ccTime addMonsterAfterDuration = 1; 
ccTime addMonsterDurationDecrementValue = 0.1; 
ccTime timeSpentSinceLastMonsterAdded = 0; 
ccTime addMonsterMinDuration =0.2; 

-(void) update:(ccTime)delta{ 

    timeSpentSinceLastMonsterAdded += delta; 
    if(timeSpentSinceLastMonsterAdded == addMonsterAfterDuration){ 
     [self addMonster]; 
     timeSpentSinceLastMonsterAdded = 0; 
     addMonsterAfterDuration -= addMonsterDurationDecrementValue; 
     if(addMonsterAfterDuration < addMonsterMinDuration){ 
       addMonsterAfterDuration = addMonsterMinDuration; 
     } 
    } 
} 

上面的例子僅用於addMonsters。我相信你可以爲遊戲中的其他物體做同樣的事情。