检测Phaser中精灵和位图之间的冲突

问题描述 投票:0回答:1

如何检测精灵与位图创建的形状之间的碰撞?

在示例中,我有精灵:

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。黄球是我的精灵。白色曲线是我从bitmapdata创建的形状。我希望检测黄色物体和白线之间的碰撞。

javascript bitmap collision-detection collision phaser-framework
1个回答
0
投票

我解决了 - 这些例子非常有用http://jsfiddle.net/4yh8ee1f/46/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个精灵(播放器和位图)时,碰撞检测非常简单。

© www.soinside.com 2019 - 2024. All rights reserved.