Jump to content

[Solved]About the player lives/ life list reduce and increase system


khleug35
 Share

Recommended Posts

Hello everyone, I am developing a platform game like Super Mario style.

I try to build a lives list system. like the photo that named "full_lives.PNG."

full_lives.PNG

i use this code to make the lives group (number of heart's icon)display on screen.

 

 //list the lives icon(number of heart's icon) on screen

  lives = game.add.group(); 
  lives.fixedToCamera = true;
  for (var i = 0; i < player_health; i++) { //player_health = 12;
  lives.create(300 - (i * 30), 0, 'live');
 }
    

When enemy collide the player or player get hurt, it remove one live in lives group and remove one heart's icon from screen 

//  When enemy collide the player or player get hurt, it remove one live in lives group and remove one heart's icon from screen 
var reduce_heart = lives.getFirstAlive();   
  player_health = player_health -1; 
     if (reduce_heart) {    
    reduce_heart.kill();
   } 

 

when the player heal his life, the lives will increase one live in lives group and one heart's icon from screen.

//when the player heal his life, the lives will increase one live in lives group and one heart's icon from screen.
var increase_heart = lives.getFirstExists(false);
   player_health = player_health +1;
    if (increase_heart)
    {
        increase_heart.revive();
    }       

Here is my Problem, The heart's icon is increase in the lives list last position, you can see the photo  that named "increase_health_icon.PNG".

increase_health_icon.PNG

var increase_heart = lives.getFirstExists(false);
   player_health = player_health +1;
    if (increase_heart)
    {
        increase_heart.revive();
    }       

This code is revive the first remove heart's icon, but I hope it can revive heart's icon reverse, How to do it???

thank you very much. I am sorry about my poor English , sorry

 

full_lives.PNG

increase_health_icon.PNG

Link to comment
Share on other sites

42 minutes ago, magig said:

Here's a little extension to Phaser.Group for example that adds the method getLastExists. The params/usage matches the getFirstExists method. The CodePen demonstrates using it for health bar:

 

OH!!!!!Super Many Thanks

Great !!! It Work for me !!!!!!!! Thanks!! magig!!!!!!!!!!

Thx for your link!!!!  My problem is solved!!!!!!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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