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:)];
  • 相关阅读:
    JS字符串函数String.replace()[转]
    分辨率和比例尺[转]
    DateDiff 函数的用法 SQL时间比较
    ASP.NET 2.0 本地化2
    ASP.NET 2.0 本地化1
    简单的分页过程,确在第10,20,30....等页,不能显示,请求帮忙,谢谢
    JQuery打造的分页无刷新的Repeater
    让flash置于DIV层之下的方法,让flash不挡住飘浮层或下拉菜单
    VS2005 + VSS6.0 简单应用示例
    SQLServer查询最近一天,三天,一周,一月,一季度方法
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3230773.html
Copyright © 2011-2022 走看看