用Laya开发微信小游戏
创建工程
编写ui界面代码:继承自ui类,然后对ui对象编写ui逻辑,比如有个页面叫TestPageUI,那么些一个类继承TestPageUI:
class TestUI extends ui.test.TestPageUI
然后在构造函数中调用自己写的ui初始化函数
给你按钮加事件:
this.btn.on(Laya.Event.CLICK, this, this.onBtnClick);
private onBtnClick(): void
{}
注意,在实例化界面对象之前,需要先加载对应的图集资源文件:
Laya.loader.load("res/atlas/comp.atlas", Handler.create(null, onLoaded));
这个路劲是相对于bin的路劲
ui类实例化完毕,需要把对象放到舞台上:
var testUI: TestUI = new TestUI();
Laya.stage.addChild(testUI);
常用代码:
显示图片:
var ape: Sprite = new Sprite();
Laya.stage.addChild(ape);
ape.loadImage("res/apes/monkey3.png");
每帧调用
Laya.timer.frameLoop(1, this, this.onLoop);