Cocos2d 应用中的 NSTimerCocos2d、NSTimer

2023-09-06 09:29:46 作者:28.这B有猫腻

在 Cocos2d 文档中写到使用 NSTimer 不是一个好主意.为什么不推荐使用 NSTimer.我知道 Cocos2d 有一个 schedule 方法.

In Cocos2d documents it is written that it is not a good idea to use NSTimer. Why is it not recommended to use NSTimer. I know there is a schedule method of Cocos2d.

推荐答案

尽量不要使用 Cocoa 的 NSTimer.而是使用 cocos2d 自己的调度器.如果你使用 cocos2d 调度器,你将拥有:

Try NOT to use Cocoa’s NSTimer. Instead use cocos2d’s own scheduler. If you use cocos2d scheduler, you will have:

自动暂停/恢复.当CCLayer(CCScene、CCSprite、CCNode)进入阶段计时器将是自动激活,当它离开舞台自动停用.你的目标/选择器将被调用增量时间

从这里(旧链接断开)http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:best_practices

更新链接http://ec2-50-16-191-191.compute-1.amazonaws.com/wiki/doku.php/prog_guide:best_practices

我要补充的是,您也增加了一些不必要的开销.如果你有很多计时器,那可能会产生很大的开销.

I would add you are adding some unwanted overhead too. If you have a lot of timers that could be a good bit of overhead.