Sign in to follow this  
Julia

Check overlap between sprites in if statement

Recommended Posts

Hey,

 

First of all I would like to thank you for the great support, learning a lot here from a great framework  :D 

I have another question:

 

Is it possible to check for an overlap between two sprites (in this case a sprite and a child from a group) in an if statement?

 

This is in my update function:

game.physics.arcade.overlap(player, enemyGroup, this.collisionHandler, null, this);

And this in my collisionHandler:

if(game.physics.arcade.overlap(player, enemyGroup.children[0])) {this.vow1();}

Share this post


Link to post
Share on other sites

Hmmm sorry but I don't understand the question... What is wrong with your code? I mean it seems to perfectly answer to your issue...

 

And I think objects need a body for the overlap method to work, so you may have to apply physics to both objects. And I'm bot sure about this but you may also want to check for collisions after your objects are updated in your update loop.

 

 

Edit : Why don't you just write :

game.physics.arcade.overlap(player, enemyGroup.children[0], this.callbackFn, null, this);

And avoir the second overlap check?

Share this post


Link to post
Share on other sites

Thanks for your answer! I guess the error should be in the vow1 function then... But you say it is possible to check for an overlap in an if statement like this?
I already have physics applied to the objects.

Share this post


Link to post
Share on other sites

I guess the code is a bit too much to place a snippet. I put a console.log in the if statement, but it isn't firing at all, so something must be wrong in the if statement I guess?

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.