我想知道如何隨着時間的推移增加間隔時間,以便我可以添加目標。我對cocos2d仍然陌生。如何增加時間間隔?
[self schedule:@selector(gameLogic:) interval:0.7];
-(void)gameLogic:(ccTime)dt {
[self addTarget];
}
我想知道如何隨着時間的推移增加間隔時間,以便我可以添加目標。我對cocos2d仍然陌生。如何增加時間間隔?
[self schedule:@selector(gameLogic:) interval:0.7];
-(void)gameLogic:(ccTime)dt {
[self addTarget];
}
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
}
爲什麼不申報一個簡單的屬性(整型,浮點等)來保存你的方法被調用的次數,並增加它,當你調用該方法本身?這樣一來,它只是一個乘法問題:
//.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_++;
}
這是' - (void)scheduleOnce:(SEL)選擇器延遲:(ccTime)延遲;'否則,你的答案應該可以正常工作! – MechEthan
謝謝,我更新了我的答案。 – EmilioPelaez