Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Object 如何从场景类访问游戏对象?_Object_Phaser Framework - Fatal编程技术网

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;
  }
}