我不熟悉phaser 3
当我扩展sprite时
它没有这样的属性
但我肯定它有这样的特性
尽管终端显示错误
这个游戏在网络上运行仍然很好
以下是我的代码
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
非常感谢!
发布于 2020-05-05 05:52:07
你扩展了一个错误的类用于启用了物理的精灵,这就是为什么你在body属性上得到一个类型错误的原因。尝试使用Phaser.Physics.Arcade.Sprite for Arcade physics Phaser.Physics.Matter.Sprite for Matter。
发布于 2020-10-04 22:48:17
也许有点晚了,只是遇到了同样的问题,我需要包装到一个类中,并键入它才能正常工作。对我来说,我使用的是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);
}
}https://stackoverflow.com/questions/58168244
复制相似问题