Jump to content

Check overlap between sprites in if statement


Julia
 Share

Recommended Posts

Hey,

 

First of all I would like to thank you all for the great support in learning about this great framework  :D 

I have another question:

Is it possible to check for an overlap in an if statement? Currently I have this 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();}

But as expected, it's not working... Is it even possible? And if yes, how?  :) 


Thanks in advance! 

 

Link to comment
Share on other sites

I'm new to this stuff, too, but I guess it is not forbidden to try to help.

 

The first use of the overlap function seems to be right. So if player hits any sprite in the enemyGroup group the collisionHandler function gets executed.

 

Now on the collisionHandler function. You get the two colliding sprites as arguments. So it looks something like

var collisionHandler = function(_player, _enemy) {  // Your code here}

What I don't get is why are you trying to check if there is an overlap between your player and the first enemy in the enemyGroup. I can think of two problems that you are trying to solve.

 

1. You want to check if the player hits the first enemy

 

Then you can put in the first enemy directly in the overlap function like this:

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

2. You want to check if the player hits any enemy

 

Then you can just remove the if part from your collisionHandler

var collisionHandler = function(_player, _enemy) {  this.vow1();}

So maybe try to describe your stuff more detailed so that I can be better help for you :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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