Jump to content

Check overlap between sprites in if statement


Julia
 Share

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();}
Link to comment
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?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...