mau649612 Posted November 24, 2014 Report 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! Quote Link to comment Share on other sites More sharing options...
lewster32 Posted November 24, 2014 Report 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 Quote Link to comment Share on other sites More sharing options...
mau649612 Posted November 24, 2014 Author Report Share Posted November 24, 2014 Do I have to use physics on my sprites to use overlap? Quote Link to comment Share on other sites More sharing options...
mau649612 Posted November 24, 2014 Author Report Share Posted November 24, 2014 For some reasong, it's always returning true... even when the sprites are not touching... Quote Link to comment Share on other sites More sharing options...
mau649612 Posted November 24, 2014 Author Report 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! Quote Link to comment Share on other sites More sharing options...
lewster32 Posted November 24, 2014 Report 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.