zoukankan      html  css  js  c++  java
  • cocos JS 定时器

    cocos2d-js的定时器的创建跟使用:

    情况一:

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. var TestLayer = cc.Layer.extend({  
    2.     sprite:null,  
    3.     ctor:function () {  
    4.         this.scheduleUpdate();  
    5.     },  
    6.     update: function () {  
    7.         //每一帧都会调用update这个函数  
    8.     }  
    9. });  

    情况二:

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. var TestLayer = cc.Layer.extend({  
    2.     sprite:null,  
    3.     ctor:function () {  
    4.         this.schedule(this.updateData,0.1);  
    5.     },  
    6.     updateData: function () {  
    7.         //会根据this.schedule第二个参数的时间来调用updataData函数  
    8.     }  
    9. });  


    cocos2d-js定时器的销毁unschedule,unscheduleAllCallbacks

    一种是针对个别的计时器销毁:unschedule通过调用的函数名销毁

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. var TestLayer = cc.Layer.extend({  
    2.     sprite:null,  
    3.     ctor:function () {  
    4.         this.schedule(this.updateData,0.1);  
    5.         this.removeSchedule()  
    6.     },  
    7.     updateData: function () {  
    8.         //会根据this.schedule第二个参数的时间来调用updataData函数  
    9.         this.unscheduleAllCallbacks()  
    10.     },  
    11.     /** 
    12.      * 删除计时器 
    13.      */  
    14.     removeSchedule: function () {  
    15.         this.unschedule(this.updateData);//通过函数名update删除  
    16.     }  
    17. });  

    unschedule,unscheduleAllCallbacks是无论有几个定时器全部都删除了:

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
      1. var TestLayer = cc.Layer.extend({  
      2.     sprite:null,  
      3.     ctor:function () {  
      4.         this.schedule(this.updateData,0.1);  
      5.         this.removeSchedule()  
      6.     },  
      7.     updateData: function () {  
      8.         //会根据this.schedule第二个参数的时间来调用updataData函数  
      9.         this.unscheduleAllCallbacks()  
      10.     },  
      11.     /** 
      12.      * 删除计时器 
      13.      */  
      14.     removeSchedule: function () {  
      15.         this.unscheduleAllCallbacks();//全部删除  
      16.     }  
      17. });  
  • 相关阅读:
    Eclipse的常见使用错误及编译错误
    Android学习笔记之Bundle
    Android牟利之道(二)广告平台的介绍
    Perl dbmopen()函数
    Perl子例程(函数)
    Perl内置操作符
    Perl正则表达式
    Linux之间配置SSH互信(SSH免密码登录)
    思科路由器NAT配置详解(转)
    Windows下查看端口被程序占用的方法
  • 原文地址:https://www.cnblogs.com/luorende/p/6723191.html
Copyright © 2011-2022 走看看