[]子容器的事件问题


// 程序入口
Laya.init(800, 800);
Laya.loader.load([{ url: "res/atlas/comp.json", type: Loader.ATLAS }], Handler.create(this, this.onLoaded));
function onLoaded(): void {
//实例UI界面
var testUI: TestUI = new TestUI();
Laya.stage.addChild(testUI);
let vhvt: ViewHeadViewTest = new ViewHeadViewTest();
//testUI.addChildAt(vhvt, 0);
testUI.addChild(vhvt);
vhvt.on(laya.events.Event.CLICK, this, (event: Laya.Event) => {
console.log("为什么这里不进来");
});
}

/**
 * ViewHeadViewTest
 */
class ViewHeadViewTest extends Laya.Sprite {
    constructor() {
        super();
        this.graphics.drawRect(0, 0, 1500, 1500, "#0000ff");

        this.on(Laya.Event.CLICK, this, this.onclickTest);

    }

    onclickTest(): void {
        console.log("单击也没有效果, why !");
    }
}


 
已邀请:

Monica - 知识达人

赞同来自:

Sprite默认是没有宽高的,你给sprite设置个宽高即可

要回复问题请先

商务合作
商务合作