2012-06-21 68 views
0

我想知道如何隨着時間的推移增加間隔時間,以便我可以添加目標。我對cocos2d仍然陌生。如何增加時間間隔?

[self schedule:@selector(gameLogic:) interval:0.7]; 



-(void)gameLogic:(ccTime)dt { 
[self addTarget]; 

} 

回答

1
float interval = .7; 

-(id)init{ 
    ... 
    [self scheduleOnce:@selector(gameLogic:) delay:interval]; //Check the name of the method, I'm not 100% sure about it 
    ... 
} 

-(void)gameLogic:(ccTime)dt { 
    [self addTarget]; 
    interval += dt; //Or whatever you want to increase it by 
    [self scheduleOnce:@selector(gameLogic:) delay:interval]; //Check the name of the method, I'm not 100% sure about it 
} 
+0

這是' - (void)scheduleOnce:(SEL)選擇器延遲:(ccTime)延遲;'否則,你的答案應該可以正常工作! – MechEthan

+0

謝謝,我更新了我的答案。 – EmilioPelaez

2

爲什麼不申報一個簡單的屬性(整型,浮點等)來保存你的方法被調用的次數,並增加它,當你調用該方法本身?這樣一來,它只是一個乘法問題:

//.h 
... 
@property (nonatomic, assign) int iterations; 
//.m 
@synthesize iterations = iterations_; 
[self schedule:@selector(gameLogic:) interval:0.7*iterations_]; 

-(void)gameLogic:(ccTime)dt { 
    [self addTarget]; 
    iterations_++; 
} 
+0

怎麼會這樣,我的朋友? – CodaFi

+0

我的歉意,我應該先閱讀頭文件! '如果選擇器已經安排好了,那麼interval參數將被更新而不需要再次安排它。'所以,你的答案也會起作用。抱歉! – MechEthan

+0

從來沒有想過這是這個簡單的大聲笑。謝謝 –