我想知道如何随着时间的推移增加间隔时间,以便我可以添加目标。我对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