Julia Posted November 6, 2014 Share Posted November 6, 2014 Hey, Just a quick question. Is it also possible to add a function to an overlap between two sprites instead of on input from the user?Something like this:var overlap = game.physics.arcade.overlap(player, enemy, this.collisionHandler, null, this);overlap.addOnce(killEnemy);killEnemy: function () {......};Thanks in advance Link to comment Share on other sites More sharing options...
lewster32 Posted November 6, 2014 Share Posted November 6, 2014 Not that way, but you can just do this:update: function() { if (enemy.alive) { // this will only run while the enemy is alive game.physics.arcade.overlap(player, enemy, this.collisionHandler, null, this); }},killEnemy: function () { enemy.kill();......};If you have multiple enemies, then you could just keep a variable separate from the enemies called something like 'enemyKilled', set it to true when an enemy dies and check for that variable insted of enemy.alive. Julia 1 Link to comment Share on other sites More sharing options...
Julia Posted November 6, 2014 Author Share Posted November 6, 2014 Thanks for your answer! I guess I was just thinking too difficult haha. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts