Julia Posted November 10, 2014 Share Posted November 10, 2014 Hey, First of all I would like to thank you all for the great support in learning about this great framework 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 More sharing options...
kasitmp Posted November 10, 2014 Share Posted November 10, 2014 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 likevar 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 collisionHandlervar 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 More sharing options...
lewster32 Posted November 10, 2014 Share Posted November 10, 2014 For what it's worth, the overlap and collide functions do return a value of either true or false depending on whether a collision took place during that test or not. Link to comment Share on other sites More sharing options...
Recommended Posts