Commit c962604a authored by 邱旭's avatar 邱旭

09.FlppyBird-节点树

parent 7a22a4dd
......@@ -81,14 +81,9 @@
this.bg1 = bg1;
this.bg2 = bg2;
this.speed = speed;
}
async start() {
super.start();
this.addChild(this.bg1);
this.addChild(this.bg2);
}
ready() {
......@@ -140,7 +135,7 @@
return Promise.all(promises);
}
async start() {
async ready() {
// 创建鸟
const bird = this.bird = new Bird();
......
......@@ -37,12 +37,6 @@ class GameObject {
this.dom.style.position = "absolute";
}
/**
* 生命周期 start 所有构造函数完成,执行此函数
*/
async start() {
}
/**
* 生命周期 start 加入显示列表执行此函数
*/
......@@ -66,11 +60,8 @@ class GameObject {
child.parent = this;
// 容错:防止子类重写的start不是async函数
// TODO dom无法在节点不在渲染树的上的时候拿到clientWidth等属性,故将start和ready放在这里
(async () => {
await child.start();
child.ready();
})();
// TODO dom无法在节点不在渲染树的上的时候拿到clientWidth等属性,故将ready放在这里
child.ready();
return child;
}
......@@ -163,7 +154,7 @@ class GameStage extends GameObject {
async _gameStart() {
await this.reloadRes();
this.start();
this.ready();
}
/**
......@@ -227,14 +218,9 @@ class Bird extends Sprite {
this.bg1 = bg1;
this.bg2 = bg2;
this.speed = speed;
}
async start() {
super.start();
this.addChild(this.bg1);
this.addChild(this.bg2);
}
ready() {
......@@ -298,7 +284,7 @@ class FlppyBird extends GameStage {
return Promise.all(promises);
}
async start() {
async ready() {
// 创建鸟
const bird = this.bird = new Bird();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment