fix(framework): check instance of Scene in PhaserScene

Ensure the scene passed to PhaserScene is an instance of Phaser.Scene
before deciding whether to instantiate it.
This commit is contained in:
hypercross 2026-04-22 00:55:38 +08:00
parent 5355afb23e
commit 887da22baa
1 changed files with 3 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import { signal, useSignal, useSignalEffect } from "@preact/signals";
import Phaser, { AUTO } from "phaser";
import Phaser, { AUTO, Scene } from "phaser";
import { createContext } from "preact";
import { useContext, useEffect, useRef } from "preact/hooks";
@ -215,7 +215,8 @@ export function PhaserScene<TData = {}>(props: PhaserSceneProps<TData>) {
const game = ctx.game;
// 注册场景到 Phaser但不启动
const scene = "scene" in props.scene ? props.scene : new props.scene();
const scene =
props.scene instanceof Scene ? props.scene : new props.scene();
const sceneKey = props.sceneKey ?? scene.sys.settings.key;
if (!game.scene.getScene(sceneKey)) {
const initData = {