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. });  
  • 相关阅读:
    区块链分布式云存储项目盘点
    区块链一定要知道的的七大认识误区
    以太坊“空块”数量激增有什么影响?
    区块链技术涉及哪些编程语言?
    一文读懂实用拜占庭容错(PBFT)算法
    清除浮动的影响
    滚动条
    分享侧栏例子
    最最最简单的轮播图(JQuery)
    3D动画
  • 原文地址:https://www.cnblogs.com/luorende/p/6723191.html
Copyright © 2011-2022 走看看