clamp

Get help using Construct 2

Post » Sun Aug 19, 2012 6:08 pm

Hi all,

I am making a Powerbar for my game, and I followed Kiyoshi's tutorial:
Make a Fancy Lifebar

I get it to work, except if the value of the bar goes into a negative number, then the bar runs outside it's container, if that makes sense?

On communicating with Kiyoshi, he mentioned the clamp function to constrain the values to within the parameters of the bar, and although I understand the concept, I do not have a clue in how to implement it.

Can anyone help?

Karl
B
22
S
8
G
5
Posts: 14
Reputation: 3,859

Post » Sun Aug 19, 2012 6:30 pm

clamp(value,minimum,maximum)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Aug 19, 2012 9:25 pm

Hi Yann,

As I said, I understand the concept of the clamp function, I have no idea how to implement it.

My .capx should be here, I have never used Dropbox before, I have just set it up so I can supply my .capx

https://www.dropbox.com/s/lly5ck2zuglkiwq/HUDDemo.capx

If that doesn't work let me know and I will try to figure it out.

So, what you are looking at are actually four bars, the blue one on top is your Power bar, the little orange one is your Grenade bar, the red one to the left of that is your Bullet bar and the box in the top left corner is your Health bar. The health bar works differently from the others, as it goes upwards instead of across.

Don't worry about the Monsters doing weird things, I can sort them later, I am just worried about the bars not constraining to their parameters.

The pickups, are mostly obvious, one for each, Power, Grenade, Bullet and Health.

So if anyone want's to have a look at my .capx and let me know how, and or where I implement the clamp function I would be very thankful.

Karl
B
22
S
8
G
5
Posts: 14
Reputation: 3,859

Post » Sun Aug 19, 2012 11:46 pm

You just need to make sure the values stay between 0 and maxvalue. At the moment you can shoot with 0 ammo and the ammo goes into negative values. You could put an 'ammo > 0' condition alongside 'on left mouse clicked' to stop that happening.

And when you add or subtract from one of the values... Instead of adding 25 to player.ammo, set player.ammo to min(player.ammo + 25, player.maxAmmo).
On grenade pickup set player.grenade to min(player.grenade + 3, player.maxGrenade) etc.

powerbars.capx (r99)ramones2012-08-19 23:48:22
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Aug 20, 2012 6:40 pm

Thanks for that ramones, I will have a proper look at that later, I've been up for about 36 hours now, and my brain is fried, lol
B
22
S
8
G
5
Posts: 14
Reputation: 3,859

Post » Mon Aug 20, 2012 6:45 pm

Haha :) I know how you feel!
ImageImage
B
74
S
17
G
6
Posts: 1,039
Reputation: 10,605

Post » Wed Aug 22, 2012 7:21 am

I may be off but you could use a,
system everytick if(ammo >= 0)then ammo = 0
to prevent going into the negative on that variable from firing if you are out of ammo. that less than or equal to equation messed me up on some debugging before. (yesterday, lol)
B
22
S
7
G
4
Posts: 14
Reputation: 4,630


Return to How do I....?

Who is online

Users browsing this forum: Vallar and 24 guests