Reputation: 23
In Phaser.js, how do I make the correct collision of irregular images, rather than the edge of the gap is also triggered by the collision too. Can the collision occur at the edge?
Upvotes: 1
Views: 1255
Reputation: 1
sprite.body.setSize(width, height, center); sprite.body.setOffset(x, y);
Upvotes: 0
Reputation: 387
You can use Arcade physics and set a smaller body inside of the sprite. For example:
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.
You can also use P2 physics and load physics so that you can use PhysicsEditor, but it's not free.
There is also Physics Body Editor. This one is very easy and handy but it's not supported Phaser yet.
Upvotes: 1
Reputation: 3385
Use the build-in P2 Physics engine and use custom shapes and polygons.
Upvotes: 0