Lifebar questions
Gamepenciler
Artist/Game DeveloperMember, PRO Posts: 326
Hello guys, I have a question about lifebars.
I want to have a character that has life that levels up
like:
Lv: 1 = 50 HP
Lv: 2 = 75 HP
Lv: 3 = 100 HP
But i want to constrain the value to a fixed with of 100 pixels
I can't find any tutorial that relates to my question. The one I found was when the life changes the width increase.
How can it should stay 100 pixels even if the life value changes?
Artist/Game Developer / Animator at your service..
Best Answer
-
Armelline Posts: 5,369
This demo I made for someone else allows you to easily change the max value of the life bar without the bar itself increasing in size.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Answers
If you have 100 pixels then I would translate your HP to percentage so that the health bar will always display the correct percentage of health.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
Ok, how do i convert it into percentage?
Artist/Game Developer / Animator at your service..
To clarify, are you wanting the HP bar to start at 100 pixels no matter the HP value and go down towards zero pixels as HP decreases? As @Summation suggested you'd constrain the width to game.HPremaining/game.HP*100.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Something like...
game.currentHP/game.maxHP
This will give you the percent, right?
For example, if my max is 100 and my current is 25, I have 25%.
The thing is... 25/100=0.25
So, the formula needs one modification.
If you multiply the result times 100...
(game.currentHP/game.maxHP) times 100
(25/100) times 100=25
If you have a health bar with 100 pixels and you display 25, you are displaying 25%.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
You may also consider rounding the result either up or down to the next whole number just to make sure (but this probably isn't necessary...?)
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
Resposting the demo for anyone who wants it, as accepting an answer hides attached files. ( @ForumNinja anything you can do about that?) Glad it could help though!
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Thanks guys: @Armelline @Summation @tatiang i think all of you have the same logic.. I will try this out soon...
Artist/Game Developer / Animator at your service..