按秒移动/旋转
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");
});
*/
}
}