【问题标题】:Cannot disable gravity for sprite in physics group in Phaser 3无法在 Phaser 3 的物理组中禁用精灵的重力
【发布时间】: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


【解决方案1】:

你也必须在组上禁用重力。

this.testGroup = this.physics.add.group({
        immovable: true,
        allowGravity: false
    });

【讨论】:

    猜你喜欢
    • 2019-08-13
    • 2021-09-28
    • 2020-11-24
    • 2021-12-21
    • 2020-01-27
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    相关资源
    最近更新 更多