zoukankan      html  css  js  c++  java
  • cocos2d与cocos2d-X中的draw和update

    像其它的游戏引擎一样,我们有两个不同的方法来完成drawupdate

            1: Draw:每一个CCNode都有一个draw方法,每一帧都会调用。我们只在这个方法里做描绘的事情。

            2: Update:默认情况下,CCNode是没有update的,如果你想要更新状态,你可以注册一个回调函数,有以下四种方式

               scheduleUpdate:

               scheduleUpdateWithPriority:

               scheduleSelector:(SEL)selector

               scheduleSelector: (SEL)selector interval:(float)interval

             注册的方法只有当前是活动的场景,并且没有Pause的情况下才会调。我们推荐使用scheduleUpdate或者scheduleUpdateWithPriority。因为它运行更快,占用内存更少。例如:

    -(id) init
    {
      // -10代表优先级,越小则优先级越高,也就越先被执行
       [self scheduleUpdateWithPriority:-10];
    }
    -(void) update:(ccTime)deltaTime
    {
       // update your node here
       // DON'T draw it, JUST update it. 
       // example:
       rotation_ = value * deltaTime;
    }
     

    调用了scheduleUpdate或者scheduleUpdateWithPriority后,系统就会去查找我们定义的update方法,相当于schedule了update方法。去除注册的update方法可以使用:

    [node unscheduleUpdate];

            我们也可以使用scheduleSelector,这是一种比较老的方式,没有优先级。如果没有interval或者当interval==0的时表示每一帧都调用。

    -(id) init
    {
       // the "step:" selector will be called every 0.5 seconds
       [self schedule:@selector(step:) interval:0.5f]
    }
     
    -(void) step:(ccTime) deltaTime
    {
       // update your stuff here
    }

    注销掉该方法:

      [node unscheduleSelector:@selector(step:)];
  • 相关阅读:
    Mac下MyEclipse安装及破解
    Mac系统安装和配置tomcat步骤详解
    android studio 导入主题设置,代码风格(附带eclipse 主题代码样式)
    电子书及阅读器Demo
    kettle大数据量读写mysql性能优化
    Git错误non-fast-forward后的冲突解决(转载)
    Mysql导出数据
    git 的使用(4)-git暂缓区工作区原理和修改删除等命令
    Lucene使用IKAnalyzer分词实例 及 IKAnalyzer扩展词库
    solr6安装部署
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3230773.html
Copyright © 2011-2022 走看看