1549469775 3 years ago
parent
commit
4e54d160a7
  1. 1
      src/Game/Stage.ts
  2. 8
      src/Game/index.ts
  3. 24
      src/main.ts
  4. 10
      src/stages/welcome/circle.ts
  5. 8
      src/stages/welcome/page_welcome.ts
  6. 5
      src/stages/welcome2/page_welcome2.ts

1
src/Game/Stage.ts

@ -93,6 +93,7 @@ export default class Stage {
name: name name: name
} }
if(type === EP.Resident){ if(type === EP.Resident){
stage.visible = false
this.gameManager.stage.addChild(stage) this.gameManager.stage.addChild(stage)
} }
return stage return stage

8
src/Game/index.ts

@ -8,10 +8,15 @@ const stageManager = Stage.getInstance();
gameManager.init(EDirection.Landscape); gameManager.init(EDirection.Landscape);
const windows: Record<string, IWindow>= {} const windows: Record<string, IWindow>= {}
const residentList: IWindow[] = []
function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP) { function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP) {
const stage = stageManager.getStage(name, type); const stage = stageManager.getStage(name, type);
const stageClass = new abstractClass(stage) const stageClass = new abstractClass(stage)
if(EP.Resident === type) {
stageClass.onLoad&&stageClass.onLoad()
residentList.push(stageClass)
}
windows[name] = stageClass windows[name] = stageClass
} }
@ -27,5 +32,6 @@ export {
gameManager, gameManager,
stageManager, stageManager,
defineWindow, defineWindow,
windows windows,
residentList,
} }

24
src/main.ts

@ -1,5 +1,5 @@
import { EP } from "./enmu"; import { EP } from "./enmu";
import { gameManager, stageManager, windows } from "./Game"; import { gameManager, stageManager, windows, residentList } from "./Game";
// @ts-ignore // @ts-ignore
const t = import.meta.globEager("./stages/**/page_*.ts"); const t = import.meta.globEager("./stages/**/page_*.ts");
@ -10,13 +10,23 @@ stageManager.watchStageChange((stage, lastStage) => {
let lastWindow = windows[lastStage.name]; let lastWindow = windows[lastStage.name];
lastWindow.onUnLoad && lastWindow.onUnLoad(); lastWindow.onUnLoad && lastWindow.onUnLoad();
} }
let curWindow = windows[stage.name]; if (stage && stage.type === EP.Normal) {
curWindow.onLoad && curWindow.onLoad(); let curWindow = windows[stage.name];
curWindow.onLoad && curWindow.onLoad();
}
}); });
gameManager.ticker.add((dt: number) => { gameManager.ticker.add((dt: number) => {
let curWindow = windows[stageManager.curStage.name]; if(stageManager.curStage){
curWindow.update && curWindow.update(dt); let curWindow = windows[stageManager.curStage.name];
gameManager.render(); residentList.forEach(v=>v.update&&v.update(dt))
curWindow.lateUpdate && curWindow.lateUpdate(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"); stageManager.initStage("welcome");

10
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{ export default new (class Circle{
render(stage: Container){ render(){
const circle = new Graphics(); const circle = new Graphics();
circle.name = "circle"; circle.name = "circle";
circle.beginFill(0xfb6a8f); circle.beginFill(0xfb6a8f);
@ -11,6 +12,9 @@ export default new (class Circle{
circle.y = 130; circle.y = 130;
circle.interactive = true; circle.interactive = true;
circle.buttonMode = true; circle.buttonMode = true;
stage.addChild(circle) circle.on("touchend", ()=>{
stageManager.changeStage("welcome2")
})
return circle
} }
}) })

8
src/stages/welcome/page_welcome.ts

@ -12,10 +12,10 @@ defineWindow("welcome", class{
} }
onLoad(){ onLoad(){
console.log("onLoad 1"); console.log("onLoad 1");
Circle.render(this.stage) this.stage.addChild(Circle.render())
let text = new Text("sda") let text = new Text("sda")
text.x = gameManager.getInfo().width-50 text.x = gameManager.getInfo().width-text.width
text.y = gameManager.getInfo().height-50 text.y = gameManager.getInfo().height-text.height
this.stage.addChild(text) this.stage.addChild(text)
} }
onUnLoad(){ onUnLoad(){
@ -24,4 +24,4 @@ defineWindow("welcome", class{
// update(){ // update(){
// console.log(22); // console.log(22);
// } // }
}, EP.Resident) })

5
src/stages/welcome2/page_welcome2.ts

@ -1,3 +1,4 @@
import { EP } from "@/enmu";
import { stageManager, gameManager,defineWindow } from "@/Game"; import { stageManager, gameManager,defineWindow } from "@/Game";
import { Graphics, Sprite, Container } from "pixi.js"; import { Graphics, Sprite, Container } from "pixi.js";
@ -12,6 +13,7 @@ circle.interactive = true;
circle.buttonMode = true; circle.buttonMode = true;
circle.on("touchend", () => { circle.on("touchend", () => {
circle.x += 10; circle.x += 10;
stageManager.changeStage("welcome")
}) })
defineWindow("welcome2", class{ defineWindow("welcome2", class{
@ -27,6 +29,5 @@ defineWindow("welcome2", class{
console.log("onUnLoad 2"); console.log("onUnLoad 2");
} }
update(){ update(){
console.log(33);
} }
}) }, EP.Resident)
Loading…
Cancel
Save