I have 2 objects.
Each object have x,y position and size (width, height).
How can i detect an collision or overlap between 2 sprites based on these parameter ?
Thanks
I have 2 objects.
Each object have x,y position and size (width, height).
How can i detect an collision or overlap between 2 sprites based on these parameter ?
Thanks
You can use the static method Phaser.Geom.Intersects.RectangleToRectangle(sprite1, sprite2) which returns a boolean in your scene’s update method.
https://photonstorm.github.io/phaser3-docs/Phaser.Geom.Intersects.html
You can use the Geom methods directly only if the game objects have origin (0, 0).
Working code
function checkOverlap(spriteA, spriteB) {
var boundsA = spriteA.getBounds();
var boundsB = spriteB.getBounds();
return Phaser.Geom.Intersects.RectangleToRectangle(boundsA, boundsB);
}