Sign in to follow this  

Check if sprite is over another sprite

Recommended Posts

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 false

both sprite1 and sprite2 is a reference for the created sprite.



Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.