0
\$\begingroup\$

So I actually have the following code that works:

var player;
var box_tnt;

function create (){
    this.physics.add.collider(player, box_tnt, hitTnt, null, this);
}

//the function hitTnt stop the game because the player died
function hitTnt (player, boxes){
   this.physics.pause();
   console.log('Game Over!');
   textGameOver.setText('GAME OVER');
   player.setTint(0xff0000);
   player.anims.play('default');
   gameOver = true;
}

and I want to do something like:

var player;
var box_tnt;

function create (){
    this.physics.add.collider(player, box_tnt, hitTnt, null, this);
}

//the function hitTnt stop the game because the player died
function hitTnt (player, boxes){
    gameOver();
    //other stuff here
}

function gameOver (){
    this.physics.pause();
    console.log('Game Over!');
    textGameOver.setText('GAME OVER');
    player.setTint(0xff0000);
    player.anims.play('default');
    gameOver = true;
}

but I have the following error message:

TypeError: gameOver is not a function

Do you have please any ideas how to do it properly?

\$\endgroup\$
1
\$\begingroup\$

gameOver = true; this overwrites gameOver; it used to be a function, now it's a boolean holding true value.

\$\endgroup\$
  • \$\begingroup\$ Thank you for making me realise this stupid mistake, know I can access the function that I renamed gameEnd(); but I still have the following error: this.physics is undefined How do I please pass this. and player. from function hitTnt to function gameEnd ? \$\endgroup\$ – Ced Feb 10 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.