在 Cocos2d 项目中使用 CCSchedulers/CCTimers
我有一个 GameController 对象,用于管理分数等内容。
分数基于用户玩了多长时间,所以我想每 2 秒将分数增加 1。所以我的 GameController 是 NSObject 的子类,我尝试使用 CCTimer 或 CCScheduler (CCTimer 似乎已贬值?)但是使用这一行,该方法永远不会触发:
[[CCScheduler sharedScheduler] scheduleSelector:@selector(updateNaturalScore:) forTarget:self interval:1 paused:NO];
我必须在 Cocos2d 对象中使用它吗?如果有的话是哪一个?或者它应该在 NSObject 子类中工作?
I have a GameController object, which is meant to manage stuff like the scores.
The score is based on how long the user has played, so I want to increase the score by one every 2 seconds. So my GameController is a subclass of NSObject, and I'm trying to use a CCTimer or CCScheduler (CCTimer seems to be depreciated?) But using this line, the method never fires:
[[CCScheduler sharedScheduler] scheduleSelector:@selector(updateNaturalScore:) forTarget:self interval:1 paused:NO];
Do I have to user this in a Cocos2d object? If so which one? Or should it work in an NSObject subclass?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个cocos2D项目吗?
你尝试过 [NSTimer ScheduleTimer...];
它将满足您的目的,因为该方法不会被触发,该类是 NSObject 它如何从 Cocos2D 框架访问类?该方法是否写在同一个类中?
Is it a cocos2D project?
have you tried [NSTimer scheduleTimer...];
it will work for your purpose, for the method not getting fired, the class being NSObject how is it accessing the classes from Cocos2D framework? Has the method written in the same class?