Mr. Meows Posted February 5, 2015 Share Posted February 5, 2015 What would be the proper way to give the player temporary invulnerability for "x" seconds after they are hit? Is there something I should do with the player object, the enemy object, the "game.physics.arcade.overlap" or the function that runs when the overlap triggers? Link to comment Share on other sites More sharing options...
jpdev Posted February 6, 2015 Share Posted February 6, 2015 You could do it this way: In the overlap callback, (where you have your 'take damage' code) you set a new variable "invulnerable" to game.time.now Before you call the "take damage" code, you check, that the difference between game.time.now and the invulnerable variable is bigger than the desired invul-time. if (game.time.now - invulnerable > 2000) { //take damage code here invulnerable = game.time.now;} This way you only take damage every two seconds. Link to comment Share on other sites More sharing options...
Recommended Posts