From 4e54d160a74e9b1f53bbdbc6f34d77b80ce299d5 Mon Sep 17 00:00:00 2001 From: 1549469775 <1549469775@qq.com> Date: Tue, 23 Nov 2021 16:20:31 +0800 Subject: [PATCH] add --- src/Game/Stage.ts | 1 + src/Game/index.ts | 8 +++++++- src/main.ts | 24 +++++++++++++++++------- src/stages/welcome/circle.ts | 10 +++++++--- src/stages/welcome/page_welcome.ts | 8 ++++---- src/stages/welcome2/page_welcome2.ts | 5 +++-- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/Game/Stage.ts b/src/Game/Stage.ts index 16c5fbb..63d90a7 100644 --- a/src/Game/Stage.ts +++ b/src/Game/Stage.ts @@ -93,6 +93,7 @@ export default class Stage { name: name } if(type === EP.Resident){ + stage.visible = false this.gameManager.stage.addChild(stage) } return stage diff --git a/src/Game/index.ts b/src/Game/index.ts index d85200d..1138bd4 100644 --- a/src/Game/index.ts +++ b/src/Game/index.ts @@ -8,10 +8,15 @@ const stageManager = Stage.getInstance(); gameManager.init(EDirection.Landscape); const windows: Record= {} +const residentList: IWindow[] = [] function defineWindow(name: string, abstractClass: Constructor, type?: EP) { const stage = stageManager.getStage(name, type); const stageClass = new abstractClass(stage) + if(EP.Resident === type) { + stageClass.onLoad&&stageClass.onLoad() + residentList.push(stageClass) + } windows[name] = stageClass } @@ -27,5 +32,6 @@ export { gameManager, stageManager, defineWindow, - windows + windows, + residentList, } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 5f214e0..3fecfb3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import { EP } from "./enmu"; -import { gameManager, stageManager, windows } from "./Game"; +import { gameManager, stageManager, windows, residentList } from "./Game"; // @ts-ignore const t = import.meta.globEager("./stages/**/page_*.ts"); @@ -10,13 +10,23 @@ stageManager.watchStageChange((stage, lastStage) => { let lastWindow = windows[lastStage.name]; lastWindow.onUnLoad && lastWindow.onUnLoad(); } - let curWindow = windows[stage.name]; - curWindow.onLoad && curWindow.onLoad(); + if (stage && stage.type === EP.Normal) { + let curWindow = windows[stage.name]; + curWindow.onLoad && curWindow.onLoad(); + } }); gameManager.ticker.add((dt: number) => { - let curWindow = windows[stageManager.curStage.name]; - curWindow.update && curWindow.update(dt); - gameManager.render(); - curWindow.lateUpdate && curWindow.lateUpdate(dt); + if(stageManager.curStage){ + let curWindow = windows[stageManager.curStage.name]; + residentList.forEach(v=>v.update&&v.update(dt)) + curWindow.update && curWindow.update(dt); + gameManager.render(); + curWindow.lateUpdate && curWindow.lateUpdate(dt); + residentList.forEach(v=>v.lateUpdate&&v.lateUpdate(dt)) + }else{ + residentList.forEach(v=>v.update&&v.update(dt)) + gameManager.render(); + residentList.forEach(v=>v.lateUpdate&&v.lateUpdate(dt)) + } }); stageManager.initStage("welcome"); diff --git a/src/stages/welcome/circle.ts b/src/stages/welcome/circle.ts index a579af4..ae8b900 100644 --- a/src/stages/welcome/circle.ts +++ b/src/stages/welcome/circle.ts @@ -1,7 +1,8 @@ -import {Container, Graphics} from "pixi.js" +import { stageManager } from "@/Game"; +import { Graphics} from "pixi.js" export default new (class Circle{ - render(stage: Container){ + render(){ const circle = new Graphics(); circle.name = "circle"; circle.beginFill(0xfb6a8f); @@ -11,6 +12,9 @@ export default new (class Circle{ circle.y = 130; circle.interactive = true; circle.buttonMode = true; - stage.addChild(circle) + circle.on("touchend", ()=>{ + stageManager.changeStage("welcome2") + }) + return circle } }) \ No newline at end of file diff --git a/src/stages/welcome/page_welcome.ts b/src/stages/welcome/page_welcome.ts index d2ccfd8..8fc6cc8 100644 --- a/src/stages/welcome/page_welcome.ts +++ b/src/stages/welcome/page_welcome.ts @@ -12,10 +12,10 @@ defineWindow("welcome", class{ } onLoad(){ console.log("onLoad 1"); - Circle.render(this.stage) + this.stage.addChild(Circle.render()) let text = new Text("sda") - text.x = gameManager.getInfo().width-50 - text.y = gameManager.getInfo().height-50 + text.x = gameManager.getInfo().width-text.width + text.y = gameManager.getInfo().height-text.height this.stage.addChild(text) } onUnLoad(){ @@ -24,4 +24,4 @@ defineWindow("welcome", class{ // update(){ // console.log(22); // } -}, EP.Resident) \ No newline at end of file +}) \ No newline at end of file diff --git a/src/stages/welcome2/page_welcome2.ts b/src/stages/welcome2/page_welcome2.ts index b789869..44cdd0f 100644 --- a/src/stages/welcome2/page_welcome2.ts +++ b/src/stages/welcome2/page_welcome2.ts @@ -1,3 +1,4 @@ +import { EP } from "@/enmu"; import { stageManager, gameManager,defineWindow } from "@/Game"; import { Graphics, Sprite, Container } from "pixi.js"; @@ -12,6 +13,7 @@ circle.interactive = true; circle.buttonMode = true; circle.on("touchend", () => { circle.x += 10; + stageManager.changeStage("welcome") }) defineWindow("welcome2", class{ @@ -27,6 +29,5 @@ defineWindow("welcome2", class{ console.log("onUnLoad 2"); } update(){ - console.log(33); } -}) \ No newline at end of file +}, EP.Resident) \ No newline at end of file