Browse Source

refactor: migrate example scene to new architecture

master
npmrun 3 weeks ago
parent
commit
c042f70d5d
  1. 62
      src/stages/welcome/page_welcome.ts

62
src/stages/welcome/page_welcome.ts

@ -1,45 +1,35 @@
import Button from "@/components/Button"; import Button from "@/components/Button";
import { gameManager, defineWindow, stageManager } from "@/Game"; import soundManager from "@/utils/Sound";
import Sound from "@/Game/Sound"; import { Container } from "pixi.js";
import { Container, Graphics, Text } from "pixi.js"; import { BaseScene } from "@/scene/BaseScene";
import { SceneType } from "@/enums/SceneType";
import position from "@/utils/Position";
import Circle from "./circle" export default class WelcomeScene extends BaseScene {
import { PWindow } from "@/Game/type"; stage: Container = new Container();
import Position from "@/Game/Position";
constructor() {
super("welcome", SceneType.Normal);
}
export default defineWindow("welcome", class extends PWindow { async layout(): Promise<void> {
stage: Container = null
text: any
layout() {
const circle = Circle.render()
this.stage.addChild(circle)
circle.on("touchend", () => {
this.changeStage("welcome2")
})
circle.on("mousedown", () => {
this.changeStage("welcome2")
})
// this.text = new Text({text: "修仙人生日常"})
// this.stage.addChild(this.text)
const btn = new Button({ const btn = new Button({
text: "修仙人生日常", position: () => Position.get("center", "center"), click: () => { text: "进入游戏",
this.changeStage("init") onClick: () => {
} this.changeScene("welcome2");
}) },
this.stage.addChild(btn._comp) position: () => position.center(),
});
this.stage.addChild(btn.container);
} }
onLoad() {
console.log("onLoad 1"); onLoad(): void {
console.log("welcome onLoad");
} }
onUnLoad() {
Sound.stop("my-sound") onUnLoad(): void {
console.log("onUnLoad 1"); soundManager.stop("my-sound");
console.log("welcome onUnLoad");
} }
update() {
// this.text.x = gameManager.getInfo().width-this.text.width
// this.text.y = gameManager.getInfo().height-this.text.height
// console.log(22);
} }
})
Loading…
Cancel
Save