cocos Creator项目笔记(一) 监听屏幕触摸事件、包围盒、实时倒计时、anim相关

1.获取当前场景名称

cc.director.getScene().name;

2.监听屏幕事件 on是开启,off是关闭

this.node.on(cc.Node.EventType.TOUCH_START, ()=>{}, this);

this.node.on(cc.Node.EventType.TOUCH_END, ()=>{}, this);

this.node.on(cc.Node.EventType.TOUCH_CANCEL, ()=>{}, this);

this.node.on(cc.Node.EventType.TOUCH_MOVE, ()=>{}, this);

3.包围盒:判断this.point是否包含在this.node的区域

//触摸屏幕获取到的是世界坐标,需要转换为局部坐标再判断
var pos = new cc.Vec2(event.getLocationX(), event.getLocationY());
this.point = this.node.convertToNodeSpaceAR(pos);
this.node.getBoundingBox().contains(this.point);

4.显示倒计时,实时更新时间

//传入需要倒计时的时间,单位秒,返回格式 5:00
    getSecond(_secondNow) {

        var _hour = parseInt(_secondNow / 3600);
        var _hourLabel = null;
        if (_hour >= 10) {
            _hourLabel = _hour;
        } else
            _hourLabel = "0" + _hour;

        var _minite = parseInt((_secondNow - _hour * 3600) / 60);
        var _miniteLabel = null;
        if (_minite >= 10) {
            _miniteLabel = _minite;
        } else
            _miniteLabel = "0" + _minite;


        var _second = parseInt(_secondNow - _hour * 3600 - _minite * 60);
        var _secondLabel = null;
        if (_second >= 10) {
            _secondLabel = _second;
        } else
            _secondLabel = "0" + _second;

        // var _string = _hourLabel + ":" + _miniteLabel + ":" + _secondLabel;
        var _string = _miniteLabel + ":" + _secondLabel;
        return _string;
    },

5.如果一个节点上挂了两个或者多个animation,并且需要在不同时机调用,调用方法:

let anim1 = this.anim.getComponent(cc.Animation);//这里anim是挂载anim动画的节点

anim1.play("这里需要填的是节点上挂的动画名字");

监听回调:

anim1.on('stop', ()=>{}, this);

anim1.on('finished', ()=>{}, this);

play : 开始播放时

stop : 停止播放时

pause : 暂停播放时

resume : 恢复播放时

lastframe : 假如动画循环次数大于 1,当动画播放到最后一帧时

finished : 动画播放完成时

6.进度条默默缩减
     

   this.schedule(() => {

            this.jindu.progress != 0 && (this.jindu.progress -= 0.005)

        }, 0.01)

7.监听spine播放完成

let spine = this.kuangda.getComponent(sp.Skeleton);
        let track = spine.setAnimation(0, 1, false);//1是指定的时间线
        if (track) {
            // 注册动画的结束回调
            spine.setCompleteListener((trackEntry, loopCount) => {
                spine.setAnimation(0, 1, true);
            });
        }

    

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值