在 Phaser 中检测精灵和位图之间的碰撞

Detect collision between sprite and bitmap in Phaser

如何检测 sprite 和位图创建的形状之间的碰撞?

例如我有精灵:

this.player = this.add.sprite(0, 0, 'player')
this.player.anchor.setTo(0.5)
this.player.scale.setTo(0.1)

和位图:

this.bmd = this.game.add.bitmapData(2000, 2000)
this.bmd.addToWorld()

然后我使用 bmd 对象绘制形状:

this.bmd.rect(px, py + 15, 5, 500, 'rgba(255, 255, 255, 1)')

然后我调用这个方法:

this.bmd.update()

它看起来或多或少像 image。 黄色球是我的精灵。 白色曲线是我从位图数据创建的形状。 我想检测黄色物体和白线之间的碰撞。

我解决了 - 这些例子很有帮助http://jsfiddle.net/4yh8ee1f/46/ and https://phaser.io/examples/v2/sprites/sprite-from-bitmapdata

var bmd = game.add.bitmapData(128,128);

bmd.ctx.beginPath();
bmd.ctx.rect(0,0,128,128);
bmd.ctx.fillStyle = '#ff0000';
bmd.ctx.fill();

var sprite = game.add.sprite(200, 200, bmd);

当我有 2 个精灵(播放器和位图)时,碰撞检测非常简单。