在游戏设计时,我们需要不断的改变屏幕显示来反映游戏操作的效果,最简单的就是提示用户已经进行的游戏时间。为此,我们需要使用cocos2d-x内置的任务调度机制,即CCNode的schedule成员函数。

void  schedule (SEL_SCHEDULE selector)
  schedules a selector. 
void  schedule (SEL_SCHEDULE selector, ccTime interval)
  schedules a custom selector with an interval time in seconds. 
void  unschedule (SEL_SCHEDULE selector)
  unschedules a custom selector. 
void  unscheduleAllSelectors (void)
  unschedule all scheduled selectors: custom selectors, and the 'update' selector. 

cocos2d-x中的schedule有两种作用:
1)定时执行方法  例如,每隔1秒就执行GameLayer类的方法step(ccTime dt)。

this->schedule(schedule_selector(GameLayer::step), 1.0f);
...
void GameLayer::step(ccTime dt)
{
...
}

2)延时执行方法  例如, 延时 5秒执行GameLayer类的方法step(ccTime dt)。

this->schedule(schedule_selector(GameLayer::step), 5.0f);
...
void GameLayer::step(ccTime dt)
{
this->unschedule(schedule_selector( GameLayer::step ));
...
}

cocos2d-x 定时器selector的使用 :schedule的使用的更多相关文章

  1. 6.cocos2d设置定时器

    T1LayerAnchorPoint.h #pragma once #include "cocos2d.h" USING_NS_CC; class T1LayerAnchorPoi ...

  2. cocos2d-x学习知识点记录

    环境搭建 http://4137613.blog.51cto.com/4127613/751149 Cocos2d-x初探,HelloWorld解读 http://www.cnblogs.com/Ke ...

  3. cocos2d JS 利用定时器实现-倒计时功能

    //创建一个定时器 cc.director.getScheduler().schedule(this, this.updates, 1, cc.REPEAT_FOREVER, 0, false, &q ...

  4. Cocos2d-x之定时器

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 每一个游戏程序都有一个循环在不断运行,它是由导演对象来管理与维护.如果需要场景中的精灵运动起来,可以在游戏循环中使用定时器对精灵等对象进行 ...

  5. Cocos2D研究院之CCNode详解(三)

    http://www.xuanyusong.com/archives/950 上一章我们了解了cocos2d的项目路径以及工作原理,这次作者要真刀真枪地讲解代码了,咱们先来看看cocos2d最常用.也 ...

  6. cocos2dx定时器

    cocos2dx三种定时器的使用以及停止schedule,scheduleUpdate,scheduleOnce 首先,什么是定时器呢?或许你有时候会想让某个函数不断的去执行,或许只是执行一次,获取你 ...

  7. Spring源码情操陶冶-任务定时器ConcurrentTaskScheduler

    承接前文Spring源码情操陶冶#task:scheduled-tasks解析器,本文在前文的基础上讲解单核心线程线程池的工作原理 应用附例 承接前文的例子,如下 <!--define bean ...

  8. Linux时间子系统之七:定时器的应用--msleep(),hrtimer_nanosleep()

    我们已经在前面几章介绍了低分辨率定时器和高精度定时器的实现原理,内核为了方便其它子系统,在时间子系统中提供了一些用于延时或调度的API,例如msleep,hrtimer_nanosleep等等,这些A ...

  9. android开发 系统时间与定时器之间有关系嘛?

    如题: android开发 系统时间与定时器之间有关系嘛? 答案:有. 看定时器源码: /* * Schedule a task. */ private void scheduleImpl(Timer ...

随机推荐

  1. android touchEvent事件学习

    学习网址:http://www.apkbus.com/forum.php?mod=viewthread&tid=44296 1:Android Touch事件传递机制解析 android系统中 ...

  2. Django -- static

    和templates一样,Django会自动去各个app根目录中寻找叫static的目录,在该目录下创建一个和app同名的目录,用于存放静态文件(js, css. images...) 使用时,只需要 ...

  3. ZEN_CART_如何添加自定义页面

    按照下面的路径,添加自己的文件,就OK了 以about us页面为例, 默认模板 \includes\templates\template_default\templates\tpl_about_us ...

  4. SQL查询重复记录

    假设现有一张人员表(表名:Person),若想将姓名.身份证号.住址这三个字段完全相同的记录查找出来,使用 1: SELECT p1.* 2: FROM persons p1,persons p2 3 ...

  5. 玩Mega8 智能充电器-12. 终于实现-dV检测(转)

    源:http://blog.chinaunix.net/uid-10701701-id-91873.html 2010.1.3 5:30终于补齐了. 电池充电的-dv 的检测系列图片请移步: http ...

  6. XML字符串解析成对象的时候应注意空格

    BomList bomList=(BomList)unmarshaller_bom.unmarshal(new StringReader(xml));xml 不能以空格开头

  7. 块和内嵌div和span

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. ftok函数的使用

    ftok函数的定义:系统建立IPC通讯 (消息队列.信号量和共享内存) 时必须指定一个ID值.通常情况下,该id值通过ftok函数得到. 头文件 #include <sys/types.h> ...

  9. HDU 3201 Build a Fence

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...

  10. ios复制到剪贴板

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...