egret.image--能在对象内自动换图片吗?
我这样写不能实现当前图片对象自动换资源
有没有办法,强制他更换呢?
class Ma extends eui.Image {
private imgArray: string[] = ['ma_1_png', 'ma_2_png', 'ma_3_png', 'ma_4_png', 'ma_5_png', 'ma_6_png', 'ma_7_png'];
public constructor() {
super();
egret.startTick(this.onUpimg, this);
}
//
protected lestTime: number = 0;
protected nowTime: number = 0;
protected onUpimg(time: number): boolean {
var dt: number = (time - this.lestTime) / 1000;
this.lestTime = time;
this.nowTime += dt;
if (this.nowTime > 1) {
this.nowTime = 0;
//换动作
var soure = this.getNowSoure();
this.source = RES.getRes(soure);
}
return false;
}
//当前资源编号
private nowSoure: number = 0;
protected getNowSoure() {
if (this.nowSoure >= this.imgArray.length - 1) {
this.nowSoure = 0;
} else {
this.nowSoure += 1;
}
return this.imgArray[this.nowSoure]
}
}
|