Phaser.js如何让不规则的图片正确碰撞,而不是边缘的缝隙也被碰撞触发
Phaser.js How to make the correct collision of irregular images, rather than the edge of the gap is also triggered by the collision too
在Phaser.js,我如何让不规则的图片正确碰撞,而不是边缘的缝隙也被碰撞触发呢。碰撞可以发生在边缘吗?
使用内置 P2 物理引擎并使用自定义形状和多边形。
您可以使用 Arcade physics 并在精灵内部设置一个较小的 body。例如:
var sprite = game.add.sprite(50,100,'mysprite');
sprite.anchor.setTo(0.5,0.5);
game.physics.arcade.enable(sprite);
// set smaller body rectangle - body.setSize(width,height,offsetX,offsetY)
sprite.body.setSize(55,110,0,2);
Official offset bounding box example.
您也可以使用 P2 物理 并加载物理以便您可以使用 PhysicsEditor,但它不是免费的。
还有Physics Body Editor。这个非常简单方便,但尚不支持 Phaser。
sprite.body.setSize(宽度,高度,中心);
sprite.body.setOffset(x, y);
在Phaser.js,我如何让不规则的图片正确碰撞,而不是边缘的缝隙也被碰撞触发呢。碰撞可以发生在边缘吗?
使用内置 P2 物理引擎并使用自定义形状和多边形。
您可以使用 Arcade physics 并在精灵内部设置一个较小的 body。例如:
var sprite = game.add.sprite(50,100,'mysprite');
sprite.anchor.setTo(0.5,0.5);
game.physics.arcade.enable(sprite);
// set smaller body rectangle - body.setSize(width,height,offsetX,offsetY)
sprite.body.setSize(55,110,0,2);
Official offset bounding box example.
您也可以使用 P2 物理 并加载物理以便您可以使用 PhysicsEditor,但它不是免费的。
还有Physics Body Editor。这个非常简单方便,但尚不支持 Phaser。
sprite.body.setSize(宽度,高度,中心); sprite.body.setOffset(x, y);