Laya 实操六:按秒移动/旋转等+缓动+TimeLine

按秒移动/旋转

export default class Test extends Laya.Script {
    constructor() { super(); }

    private self: any = null;
 
    onAwake(){
        this.self = this.owner;
    }

    onUpdate(){
        //this.self.x += 100 * Laya.timer.delta/1000;//移动
        //this.self.rotation += 30 * Laya.timer.delta/1000;//旋转

        //斜行
        /*
        this.self.x += 100 * Laya.timer.delta/1000 * Math.cos(45 * Math.PI/180);
        this.self.y += 100 * Laya.timer.delta/1000 * Math.sin(45 * Math.PI/180);
        */
    }
}

缓动

export default class Test extends Laya.Script {
    constructor() { super(); }

    private self: any = null;
 
    onAwake(){
        this.self = this.owner;
    }

    onStart(){
        //Laya.Tween.from(this.owner,{x:500,y:500},2000,null);//位置从参数状态到当前状态
        //Laya.Tween.to(this.owner,{x:500,y:500},2000,null);//位置从当前状态到参数状态
        //Laya.Tween.to(this.owner,{x:500,y:500,rotation:180},2000,null);//位置+旋转
        //Laya.Tween.to(this.owner,{x:500,y:500,rotation:90,scaleX:0.2,scaleY:0.2},2000,null);//位置+旋转+缩放

        //停止并清理缓动
        //let t = Laya.Tween.from(this.owner,{x:500,y:500},5000,null);
        //Laya.timer.once(1000,this,function () {
            //t.clear();
            //Laya.Tween.clear(t);
            //Laya.Tween.clearAll(this.owner);
            //t.complete();//立即结束并设置到目标状态
        //});

        //加入回调
        /*
        let func = Laya.Handler.create(this,function () {
            console.log("ok");
        });
        Laya.Tween.from(this.owner,{x:500,y:500},2000,null,func);
        */

        //延时
        /*
        let func = Laya.Handler.create(this,function () {
            console.log("ok");
        });
        Laya.Tween.from(this.owner,{x:500,y:500},2000,null,func,3000);
        */

        //暂停pause
        //重新开始restart
        //暂停恢复resume
        //设置开始时间setStartTime
        //……

        //缓动类型
        //Laya.Tween.from(this.owner,{x:500,y:500},2000,Laya.Ease.backOut);

        //比例执行+执行次数+状态更新函数
        /*
        let t = Laya.Tween.from(this.owner,{x:700,y:500},2000,Laya.Ease.backOut);
        t.progress = 0.3;//比例执行
        t.repeat = 3;//执行次数,为0时无线循环
        t.update = Laya.Handler.create(this,()=>{console.log("ok")});//状态更新函数
        */
    }
}

TimeLine

export default class Test extends Laya.Script {
    constructor() { super(); }

    onStart(){
        //普通
        /*
        let tl = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},2000,null);
        tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
        //tl.play(0);//播放一次
        tl.play(0,true);//循环播放
        */

        //带延时
        /*
        let tl = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},2000,null);
        tl.to(this.owner,{scaleX:1,scaleY:1},2000,null,3000);//延时3s
        tl.play(0);//播放一次
        */

        //使结束
        /*
        let tl = Laya.TimeLine.to(this.owner,{scaleX:0,scaleY:0},2000,null);
        tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
        tl.play(0,true);
        Laya.timer.once(8000,this,function(){
            tl.destroy();//结束
            this.owner.scaleX = 0.5;
            this.owner.scaleY = 0.5;
        });
        */

        //带事件
        /*
        let tl = new Laya.TimeLine();
        tl.to(this.owner,{scaleX:0,scaleY:0},2000,null);
        tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
        tl.play(0);
        tl.on(Laya.Event.COMPLETE,this,function(){
            console.log("ok");
        });
        */

        //带标签
        /*
        let tl = new Laya.TimeLine();
        tl.to(this.owner,{scaleX:0,scaleY:0},2000,null);
        tl.addLabel("aaa",0);
        tl.on(Laya.Event.LABEL,this,function(p){
            console.log("o",p);
        });
        tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
        tl.play(0);
        tl.on(Laya.Event.COMPLETE,this,function(){
            console.log("k");
        });
        */

        /*
        let tl = new Laya.TimeLine();
        tl.to(this.owner,{scaleX:0,scaleY:0},2000,null);
        tl.addLabel("aaa",0);
        tl.on(Laya.Event.LABEL,this,function(p){
            console.log("o",p);
        });
        tl.to(this.owner,{scaleX:1,scaleY:1},2000,null);
        tl.play("aaa");
        tl.on(Laya.Event.COMPLETE,this,function(){
            console.log("k");
        });
        */
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值