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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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