0

我想知道如何随着时间的推移增加间隔,以便添加目标。我还是 cocos2d 的新手。

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



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

}
4

2 回答 2

2

为什么不声明一个简单的属性(int、float 等)来保存方法被调用的次数,并在调用方法本身时增加它?这样,这只是一个乘法问题:

//.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_++;
}
于 2012-06-21T19:34:22.440 回答
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
}
于 2012-06-21T19:36:58.890 回答