How do I keep health bar width constant?

Just started using Construct 2? Post your questions here

Post » Fri Feb 27, 2015 6:07 pm

I want to make health bar like a RPG games, or like other games, it's familiar (Dota/ Tera /Zenonia).
So far I'm using set width but this is not what I want
youtube.com/watch?v=DFUrc6eNsIg
So if I use this tutorial, if my max hp player larger than layout, it's become bad.
All I want is keep the width, no matter how much I add number of HP.
I need some advice.
Sorry for my english and thank you for your help.
You do not have the required permissions to view the files attached to this post.
B
6
S
1
Posts: 24
Reputation: 448

Post » Fri Feb 27, 2015 6:45 pm

You can use percent instead. So the length of the green health bar is 100% when its full and if you get hit you subtract the amount from the health bar in percent.

So if your HP is set to 100 and you get hit by an enemy causing -10HP you subtract 10% of the length of the bar.

And when you're high level and your HP is set to maybe 1000 and you get hit by the same enemy causing -10HP you only subtract 1% of the healthbars length.
B
46
S
19
G
10
Posts: 659
Reputation: 10,128

Post » Fri Feb 27, 2015 7:08 pm

So in case Anon's response wasn't clear for how to do that, you should set the bar's width to (current health/max health)*maximum length. You can also get fancy and use lerp or some other operation to make it smoothly change there. So, for instance,

Set width to lerp(self.width, (current health/max health)*maximum length, 5*dt) where 5 would generally change how quickly it gets there.

I've attached a quick example of how to do it. I changed the green bar to a Tiled Background object so that it won't get the blurred edges you get from stretching out a sprite.

Healthbar problemFIX.capx
You do not have the required permissions to view the files attached to this post.
B
100
S
36
G
16
Posts: 947
Reputation: 16,219

Post » Fri Feb 27, 2015 8:02 pm

Anonnymitet wrote:You can use percent instead. So the length of the green health bar is 100% when its full and if you get hit you subtract the amount from the health bar in percent.

So if your HP is set to 100 and you get hit by an enemy causing -10HP you subtract 10% of the length of the bar.

And when you're high level and your HP is set to maybe 1000 and you get hit by the same enemy causing -10HP you only subtract 1% of the healthbars length.



C-7 wrote:So in case Anon's response wasn't clear for how to do that, you should set the bar's width to (current health/max health)*maximum length. You can also get fancy and use lerp or some other operation to make it smoothly change there. So, for instance,

Set width to lerp(self.width, (current health/max health)*maximum length, 5*dt) where 5 would generally change how quickly it gets there.

I've attached a quick example of how to do it. I changed the green bar to a Tiled Background object so that it won't get the blurred edges you get from stretching out a sprite.


Thank you for help guys,
@C-7 I can't open your project because mine older version.. But set width with lerp is a new lesson for me. It's really cool. I had change my project. please check if it's the same thing.
You do not have the required permissions to view the files attached to this post.
B
6
S
1
Posts: 24
Reputation: 448

Post » Sat Feb 28, 2015 1:48 am

Yeah, that looks pretty similar. Here's a screenshot of the event sheet: (relatively large image). I simplified things somewhat from how you had it, particularly the start of layout event and the "every tick" one at the bottom. I also changed the values applied by the buttons just for ease of testing.
B
100
S
36
G
16
Posts: 947
Reputation: 16,219


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest