2012-06-21 66 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

从来没有想过这是这个简单的大声笑。谢谢 –