没办法才用NSTimer的。但是如何在cocos2d-x里面使用NSTimer呢?请大家帮帮忙。
兄弟,这个问题我也遇到过了,我是这样处理的 首先声明一个全局的变量nowTime。 然后在AppController.mm里面的
didFinishLaunchingWithOptions方法最后加上
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: 1
target: self
selector: @selector(handleTimer:)
userInfo: nil
repeats: YES];
在加个这个方法
- (void) handleTimer: (NSTimer *) timer
{
nowTime++;
}。
这样退到后台nowTime也会自加的。每个页面都可以访问nowTime。
【转自】http://www.cocoachina.com/ask/questions/show/98978/cocos2d-x%E4%B8%AD%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8NSTimer

本文介绍了一种在Cocos2d-x中使用NSTimer的方法,通过设置全局变量nowTime并在AppController.mm的didFinishLaunchingWithOptions方法中创建定时器,实现即使在后台nowTime也能自增的功能。
9万+

被折叠的 条评论
为什么被折叠?



