Jump to content

Arcade.overlap returning true on false overlap


predator
 Share

Recommended Posts

When two sprites are overlapped, they call this function.

killEnemy: function(player, enemy) {
    if (enemy.body.touching.up)
    {
        enemy.kill();
    }
    else
    {
        return false;
    }
}

However, even if the enemy is not being touched on the top, as soon as there is an overlap, the enemy is killed. Why does this happen?

Link to comment
Share on other sites

The overlap function is

this.physics.arcade.overlap(this.player, this.enemies, this.killEnemy);

The enemy is in a group called enemies.

I think I worded the question wrong, the problem is in the 

this.enemy.body.touching.up

part of the code. In the console, I set it up to print the value, and when the player is touching it, it goes 'false' then 'true' twice, like 'false true true false true true false true true' et cetera.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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