I found out a video talking about health bar:
Which technically just construct the X value to the centre.
But it could only works when it locked on the left side and decrease from right side.
Then how do I make a heath bar that locked on the right side and decrease from left side?
@Spalding004 said:
Typically the way you would make a health bar like that would be to constrain its X position to
(where you want it centered)-(the width of the bar)*(1/2)
Or, you can make it easy on yourself and use a replicate behavior on a small actor like this:
number of copies: (health attribute)
replicate direction: left
so when you have full health, the the bar is a certain length and as health decreases it dynamically shrinks.
Or, if you wanted the bar to only be a certain length, under # of copies you could use this expression:
(current health of character/full health of character)*(max width you want for the bar)
which would result in a health bar of whatever length you wanted.
I'm assuming here a 1px wide actor. If you wanted a thicker actor for whatever reason you'd need to adjust the expression a bit.
I see..But I guess using this method will be adjusted by the device resolution? Some device might have 1000 pixel but some might have 5000... will this still work?
Comments
Typically the way you would make a health bar like that would be to constrain its X position to
(where you want it centered)-(the width of the bar)*(1/2)
Or, you can make it easy on yourself and use a replicate behavior on a small actor like this:
number of copies: (health attribute)
replicate direction: left
so when you have full health, the the bar is a certain length and as health decreases it dynamically shrinks.
Or, if you wanted the bar to only be a certain length, under # of copies you could use this expression:
(current health of character/full health of character)*(max width you want for the bar)
which would result in a health bar of whatever length you wanted.
I'm assuming here a 1px wide actor. If you wanted a thicker actor for whatever reason you'd need to adjust the expression a bit.
I have a drop dead simple health bar tutorial below. It uses the Replicate Behavior so you can change the direction really easily.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
I see. But is this way you provided has a lack of performance? Replicate in 1 pixel sounds..A lot of works to do for the engine.
I see..But I guess using this method will be adjusted by the device resolution? Some device might have 1000 pixel but some might have 5000... will this still work?
Replicate works super fast, I wouldn't worry about any kind of performace hit. Its easy enough to incorporate, try it out and see.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Replicate is super light on the engine.
Mental Donkey Games
Website - Facebook - Twitter