我正在尝试将我的项目更新到 Cocos2d v3。我想知道如何实现每帧运行的更新方法。
这里https://www.makegameswith.us/gamernews/359/cocos2d-30-a-brief-transition-guide有信息表明不需要 [self ScheduleUpdate];
调用,只需添加方法
- (void)update:(CCTime)delta {
...
}
我猜这个方法将在场景加载时运行每一帧。但是,如果我想在其他事件之后开始安排该怎么办?例如,按下按钮,或启动,然后停止,然后再次重新运行?
还有ccTime呢?它只是重命名为CCTime?
最佳答案
是的,update
方法每帧都会运行。
如果您想根据游戏状态有不同的行为,您可以简单地使用 if
或 switch
,特别是如果您的游戏很简单。
如果更复杂,您可以随时选择不同的方法来运行。
这是我的选择器属性
// The update selector used depending on state
@property (nonatomic, assign) SEL updateSelector;
以及我的更新方法
- (void) update:(CCTime)delta
{
if (self.updateSelector != nil)
{
IMP imp = [self methodForSelector:self.updateSelector];
void (*func)(id, SEL) = (void *)imp;
func(self, self.updateSelector);
}
}
我根据我的状态设置了不同的更新选择器。
关于cocos2d-iphone - 如何实现每帧运行的更新方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22509239/