mau649612 Posted November 24, 2014 Share Posted November 24, 2014 Hello guys, is there a easy way if is an sprite over another sprite? For example, in my game I can put 2 sprites in the world with random positions, but they must not cover up each other... I have a reference for both objects, so I was wondering if can I do something like this:Phaser.Sprite.over(sprite1, sprite2); // true or falseboth sprite1 and sprite2 is a reference for the created sprite. Thanks! Link to comment Share on other sites More sharing options...
lewster32 Posted November 24, 2014 Share Posted November 24, 2014 Yep, Sprite.overlap does this: if (sprite1.overlap(sprite2)) { // do something...}Of course if you're using physics you also have all of their overlapping and collision detection routines too, but the above feature is provided for quick 'bounds overlapping' checks such as this. marros1812 1 Link to comment Share on other sites More sharing options...
mau649612 Posted November 24, 2014 Author Share Posted November 24, 2014 Do I have to use physics on my sprites to use overlap? Link to comment Share on other sites More sharing options...
mau649612 Posted November 24, 2014 Author Share Posted November 24, 2014 For some reasong, it's always returning true... even when the sprites are not touching... Link to comment Share on other sites More sharing options...
mau649612 Posted November 24, 2014 Author Share Posted November 24, 2014 Got it working... I had to use a timeout when calling overlap, because it was checking it too fast, before the sprites were in the game canvas. Thanks! Link to comment Share on other sites More sharing options...
lewster32 Posted November 24, 2014 Share Posted November 24, 2014 Don't use timeouts if you can help it in Phaser, try to do everything in the update loop or at the very least use the built in Phaser.Timer to set delays - game.time is a convenient instance of Timer ready to use. Link to comment Share on other sites More sharing options...
Recommended Posts