【发布时间】:2019-09-18 07:42:26
【问题描述】:
我正在 Phaser 3 中创建一个新的物理组,为我的游戏提供平台。
this.testGroup = this.physics.add.group({ runChildUpdate: true })
我正在向这个组添加一个平台精灵:
this.testGroup.add(new Platform(this, 400, 400, "platform"), true)
而且,在精灵中,我正在尽我所能将重力设置为 0
export class Platform extends Phaser.Physics.Arcade.Sprite {
constructor(scene) {
super(scene, 100, 100, "texture")
this.scene.physics.add.existing(this)
this.body.setAllowGravity(false)
this.setGravity(0)
this.setImmovable(true)
this.setVelocityY(0)
}
}
但是这些选项都没有任何效果,运行游戏时平台还是直接掉下来。
如果我将对象添加到物理组,为什么不能将重力设置为 0?
【问题讨论】:
-
试试
this.body.allowGravity = false而不是this.body.setAllowGravity(false)
标签: typescript phaser-framework