[]Handler.create的回收问题
Handler.create的最后一个参数,官方解释是 once:Boolean (default = true) — 是否只执行一次,如果为true,回调后执行recover()进行回收,默认为true。可下面代码为什么结果是false?
module laya {
import Stage = Laya.Stage;
import Text = Laya.Text;
import Browser = Laya.Browser;
import WebGL = Laya.WebGL;
export class Test {
private h1: Laya.Handler;
private h2: Laya.Handler;
constructor() {
// 不支持WebGL时自动切换至Canvas
Laya.init(Browser.clientWidth, Browser.clientHeight, WebGL);
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
Laya.stage.bgColor = "#232628";
this.h1 = Laya.Handler.create(this, this.loadPicComplete, null, true);
Laya.loader.load("res/img/1.png", this.h1);
}
private loadPicComplete(): void {
Laya.timer.once(2000, this, this.actT);
}
private actT(): void {
this.h2 = Laya.Handler.create(this, this.loadPicComplete, null, true);
console.log(this.h1 == this.h2);//为什么是false
}
}
}
new laya.Test();
module laya {
import Stage = Laya.Stage;
import Text = Laya.Text;
import Browser = Laya.Browser;
import WebGL = Laya.WebGL;
export class Test {
private h1: Laya.Handler;
private h2: Laya.Handler;
constructor() {
// 不支持WebGL时自动切换至Canvas
Laya.init(Browser.clientWidth, Browser.clientHeight, WebGL);
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
Laya.stage.bgColor = "#232628";
this.h1 = Laya.Handler.create(this, this.loadPicComplete, null, true);
Laya.loader.load("res/img/1.png", this.h1);
}
private loadPicComplete(): void {
Laya.timer.once(2000, this, this.actT);
}
private actT(): void {
this.h2 = Laya.Handler.create(this, this.loadPicComplete, null, true);
console.log(this.h1 == this.h2);//为什么是false
}
}
}
new laya.Test();
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
cheche062
赞同来自: