1549469775 3 years ago
parent
commit
4e54d160a7
  1. 1
      src/Game/Stage.ts
  2. 8
      src/Game/index.ts
  3. 12
      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
}
if(type === EP.Resident){
stage.visible = false
this.gameManager.stage.addChild(stage)
}
return stage

8
src/Game/index.ts

@ -8,10 +8,15 @@ const stageManager = Stage.getInstance();
gameManager.init(EDirection.Landscape);
const windows: Record<string, IWindow>= {}
const residentList: IWindow[] = []
function defineWindow(name: string, abstractClass: Constructor<IWindow>, 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,
}

12
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();
}
if (stage && stage.type === EP.Normal) {
let curWindow = windows[stage.name];
curWindow.onLoad && curWindow.onLoad();
}
});
gameManager.ticker.add((dt: number) => {
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");

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{
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
}
})

8
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)
})

5
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);
}
})
}, EP.Resident)
Loading…
Cancel
Save