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