一、什麼是RunTime?
在LayaAirIDE中資源面板下所有的組件均有runtime的屬性,runtime是該組件運行時的邏輯類;相同組件可使用同一runtime類來實現相同的功能,比如不同頁面上需要對相同的組件實現同一功能。需要注意的是組件的runtime邏輯類如果不繼承組件自身,並且繼承的對象中沒有該組件的屬性時,這個屬性則會失效(不支持在View和Dialog頁面中使用)
二、代碼如下
export default class RunTimeTest extends Laya.Image {
constructor() {
super();
this.anchorX=0.5;
this.anchorY=0.5;
this.on(Laya.Event.MOUSE_DOWN,this,this.mouseDown);
Laya.stage.on(Laya.Event.MOUSE_UP,this,this.mouseUp);
}
mouseDown() {
Laya.Tween.to(this,{scaleX:0.5,scaleY:0.5},100);
}
mouseUp(){
Laya.Tween.to(this,{scaleX:1,scaleY:1},100);
}
}
參考資料:
laya自定義自己的UI基類 以及runtime的使用:https://blog.csdn.net/weixin_41316824/article/details/86550544