Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Remove Sprites in certain order.


Heppell08
 Share

Recommended Posts

Just a question on how people are doing there HP bars? In my game i have 5 hearts placed above the players head. The heart 'SHOULD' be removed when the criteria is met but this apparently doesn't work.

What i have done is create a group. Within the group i purposely created 5 seperate vars for each seperate heart to make it easier for the removal. 

Each heart is scaled down and the player is the parent of the group so that the it follows above the head. This is all working except from the hearts being removed when asked to.

I have code below whats happening in my update for the hearts to go away but they just done...

  if(player.health > 40 && player.health < 49)    {        heart1.kill();    }     if(player.health > 30 && player.health < 40)    {         heart2.kill();      }    if(player.health > 20 && player.health < 30)    {           heart3.kill();    }    if(player.health > 10 && player.health < 20)    {        heart4.kill();    }    if(player.health > 0 && player.health < 10)    {        heart5.kill();    }    if(player.health < 1)    {        deathtext.visible = true;        restarttext.visible = true;    }

Might also be worth noting that the deathtext and restart text dont appear after the crireria is met too. This is nothing to do with the switch from 113 to 114 because its still the same issue irrelevant to my phaser versioning.

Also it would be very helpful if there was a snip of code for restarting a state after death. My function just 'starts' the state with the background and my floating sprite in the background and thats all. None of the scenery, player or enemies spawn in. Thanks :)

Link to comment
Share on other sites

  • 2 weeks later...

First off your if statements have situations that would not trigger a heart removal. For example if the health is exactly 40 none of the statements return true as you only check for greater than and less than.

What scope are your variables being created? I'd start with confirming the if statements are working and then checking the scope.

Link to comment
Share on other sites

The health was being removed in blocks for certain difficulty so the 40 only health stood true when heart 1 was removed to have 4 hearts remaining and ready to be removed after taking damage. I've dince fixed this by changing the groups creation system. Instead of having it as heartgroup.create(0,5,'heart);

I changed my whole group coding to a main group that parented the player and then added hearts in as sprites instead of group creations. Then just added the alread pre created sprite to the group for the eventual removal in that update code. Thank for the response though :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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