【问题标题】:Phaser 3 Phaser.GameObjects.Sprite body not foundPhaser 3 Phaser.GameObjects.Sprite body not found
【发布时间】:2020-01-29 18:27:32
【问题描述】:

我是 Phaser 3 的新手

当我扩展精灵时

结果没有这样的属性

但我确定它有这个属性

虽然终端显示错误

游戏仍然在网络上运行良好

这是我的代码

export class Planet2 extends Phaser.GameObjects.Sprite {
    cellWidth: number;
    cellHeight: number;


    constructor(config) {
        super(config.scene, config.x, config.y, 'planet2');

        config.scene.physics.world.enable(this);
        config.scene.add.existing(this);

        this.body.allowGravity = false;

        this.cellWidth = config.scene.cameras.main.width / 100;

        this.body.moves = true;
        this.body.offset.x = this.cellWidth * 2;
        this.body.setSize(this.cellWidth * 8, this.cellWidth * 8, 0, 0);
        this.body.isCircle = true;


    }


}

这里是github https://github.com/lalalalaluk/ion-phaser-test.git

非常感谢!

【问题讨论】:

  • 您需要添加 Phaser 打字稿定义文件。从 Phaser 源 github.com/photonstorm/phaser?files=1 下载并添加类型文件夹或尝试将 Phaser 包更新到最新版本 3.20.0
  • 我尝试将移相器更新到 3.20.0 它不起作用

标签: angular phaser-framework


【解决方案1】:

您扩展了错误的类以用于启用物理的精灵,这就是您在 body 属性上收到类型错误的原因。尝试 Phaser.Physics.Arcade.Sprite 用于街机物理 Phaser.Physics.Matter.Sprite 用于物质物理。

【讨论】:

    【解决方案2】:

    也许有点晚了,刚刚遇到同样的问题,我需要将其包装到一个类中并输入它以使其工作。对我来说,我正在使用 Arcade 物理。

    class Planet2 extends Phaser.GameObjects.Sprite {
        body: Phaser.Physics.Arcade.Body;
    
        constructor(scene, x = 0, y = 0, key = '') {
            super(scene, x, y, key);
    
            scene.physics.world.enableBody(this);
            this.body.setAllowGravity(false);
            scene.add.existing(this);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 2021-12-27
      • 1970-01-01
      • 2020-01-06
      • 2019-05-02
      • 1970-01-01
      • 2019-05-12
      相关资源
      最近更新 更多