NSTimer in Cocos2d Application

后端 未结 1 1858
抹茶落季
抹茶落季 2021-01-14 08:41

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.

相关标签:
1条回答
  • 2021-01-14 09:02

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

    • automatic pause/resume.
    • when the CCLayer (CCScene, CCSprite, CCNode) enters the stage the timer will be
      • automatically activated, and when it leaves the stage it will be
      • automatically deactivated. Your target/selector will be called with a delta time

    from here (old broken link) http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:best_practices

    updated link 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.

    0 讨论(0)
提交回复
热议问题