Object 如何从场景类访问游戏对象?
怎么 在函数体中 这是一个成员场景对象类 在游戏对象配置中作为值列出Object 如何从场景类访问游戏对象?,object,phaser-framework,Object,Phaser Framework,怎么 在函数体中 这是一个成员场景对象类 在游戏对象配置中作为值列出 const config: Phaser.Types.Core.GameConfig = { scene: MainScene, ... 我能得到游戏对象的参考吗 如果我想像这样从指针获取值: export class MainScene extends Phaser.Scene { private foo; constructor() { super({ key: "MainScene" })
const config: Phaser.Types.Core.GameConfig = {
scene: MainScene,
...
我能得到游戏对象的参考吗
如果我想像这样从指针获取值:
export class MainScene extends Phaser.Scene {
private foo;
constructor() {
super({ key: "MainScene" });
this.foo = game.input.mousePointer;
}
假设场景和游戏对象位于不同的ts文件中
?尝试
console.log(主场景)代码>并对其进行梳理。我不太清楚您想要完成什么?您可以使用this.sys.game
在任何场景中访问游戏对象。但是,这在场景的构造函数中不可用。您应该将场景设置移动到init
函数,当游戏对象可用时,框架将自动调用该函数
通过此更改,您的示例将如下所示:
export class MainScene extends Phaser.Scene {
private foo;
constructor() {
super({ key: "MainScene" });
}
init() {
this.foo = this.sys.game.input.mousePointer;
}
}