cocos2d 中scheduleUpdate和scheduleUpdateWithPriority对比

来源:互联网 发布:php 报名缴费 源码 编辑:程序博客网 时间:2024/06/07 07:23

============================================================
博文原创,转载请声明出处
电子咖啡(原id蓝岩)
============================================================

cocosd中CCLayer提供schedule方法来进行帧刷新,默认频率为1秒60帧,如下:

init {  [self schedule:@selector(tick:)];}-(void) tick:(ccTime)dt{  // update your stuff here}

同时cocos2d v0.99.还提供了以下两种更有效的方法来刷新帧。

[self scheduleUpdate];  // use priority == 0 ---A[self scheduleUpdateWithPriority:an_integer]; ----B
然后在cclayer子类中实现update方法。
-(void) update:(ccTime)deltaTime{    // Update your stuff here}

新老方法有什么不同呢?

  1. 新方法提供了优先级可供选择,意味着你可以为n哥update方法排一下先后执行的顺序
  2. 新方法可以节省一些内存,同时每次更新时候更加迅速