CVP认证学习笔记--李天宇010节点的计划任务

本节课的学习内容是节点的计划任务。我通过翻阅API

var schedule(

var selector,

var interval,

var repeat,

var delay

)

指定一个以秒为单位的时间间隔并定义一个自定义选择器。本节课的作业是通过点击一个按钮实现一个让node进行旋转和暂停的实验。我的代码如下:

 

var HelloWorldLayer = cc.Layer.extend({

    sprite:null,

    ctor:function () {

        this._super();

        var logo=new cc.Sprite(res.HelloWorld_png);

        logo.setAnchorPoint(0,0);

        this.addChild(logo);

        logo.setTag(111);

        logo.setPosition(cc.winSize.width/2,cc.winSize.height/2);

        var itemstart=new cc.MenuItemFont("启动",this.start,this);

        var itemstop=new cc.MenuItemFont("停止",this.stop,this);

        itemstop.setPositionY(50);

        var menu=new cc.Menu(itemstart,itemstop);

        menu.setAnchorPoint(0,0);

        menu.setPosition(100,100);

        this.addChild(menu);

        return true;

    },

    start:function()

    {

        this.schedule(this.update);

    },

    stop:function(){

        this.unschedule(this.update);

    },

    update:function(){

        var nowlogo=this.getChildByTag(111);

        nowlogo.setRotation(nowlogo.getRotation()+1);

    }

});

 

var HelloWorldScene = cc.Scene.extend({

    onEnter:function () {

        this._super();

        var layer = new HelloWorldLayer();

        this.addChild(layer);

    }

});

 

最重要的就是this.schedule(this.方法名称);来实现定时器的加载.停止是用unschedule。最后附上作业链接:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值