Jump to content

Kill Mechanics Lives/Health


lenlac
 Share

Recommended Posts

Could someone give me some advice on how to do this best?

 

I have tried a few options but i have not been able to get the function to update the variable correctly:

        collideEnemyPlain: function(player, dark){            if(dark.body.touching.up) {                player.body.velocity.y = -200;                dark.kill();            } else {                player.body.x = player.body.x - 50;                player.body.y = player.body.y - 50;                            }                                                   }

I have the function above and i tried to:

        collideEnemyPlain: function(player, dark){            if(dark.body.touching.up) {                player.body.velocity.y = -200;                dark.kill();            } else if (this.lives === 0) {                player.body.x = player.body.x - 50;                player.body.y = player.body.y - 50;                player.kill();            } else {                player.body.x = player.body.x - 100;                player.body.y = player.body.y - 100;                this.lives -= 1;                           }}

I can trigger only the If Statement or the Else statement. I fail to trigger the Else If Statement.

 

The variable "lives" is initialized in the function: create area with a initial value of 3.

 

I am dont get errors, but i am pretty sure i dont understand how to get the variable "lives" linked properly from the function to the variable's value.

 

 

 

Ty in Advance for any help or examples i can hunt down and study.

Link to comment
Share on other sites

this.physics.arcade.collide(this.player, this.evilcoin, this.collideEnemyPlain);To the Following:this.physics.arcade.collide(this.player, this.evilcoin, this.collideEnemyPlain, null, this);

I got it to work! was syntax :) got it to work by changing those properties on the collide function.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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