khleug35 Posted September 11, 2017 Share Posted September 11, 2017 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." 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". 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 Link to comment Share on other sites More sharing options...
Taz Posted September 11, 2017 Share Posted September 11, 2017 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: Link to comment Share on other sites More sharing options...
khleug35 Posted September 11, 2017 Author Share Posted September 11, 2017 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 More sharing options...
Recommended Posts