街机物理碰撞不会与墙壁水平碰撞吗?

时间:2020-04-02 07:06:28

标签: javascript phaser-framework

我有一个我无法弄清的错误/逻辑错误。我的播放器确实检测到与顶部和底部(而不是侧面)的瓦片碰撞。播放器是扩展Phaser.GameObjects.Rectangle的类的实例。我尝试将其更改为Phaser.GameObjects.Sprite,但发生相同的问题。

this.player.body.collideWorldBounds = true
this.foregroundLayer.setCollisionBetween(1, 200)
this.physics.add.collider(this.player, this.foregroundLayer)

在更新方法中

this.physics.collide(this.player, this.foregroundLayer)

enter image description here

橙色是debugGraphics,如您所见,播放器(框)不会与瓷砖水平碰撞。是什么原因造成的? TIA。

1 个答案:

答案 0 :(得分:1)

欢迎,错误是我如何定义机芯。我必须使用

this.body.x += this.speed

代替

this.x += this.speed