How do I make a "100%" indicator relative to a value?

Get help using Construct 2

Post » Wed Jul 02, 2014 12:06 pm

Hi again friends,

I got a golf game where the power of the shot is equal to the distance between the mouse position and the ball position (with limitations, obviously).

Now, the bar, for example, can be 300px long but I want to show a number with the percentage of the power.

I'm horrible at maths xD
B
5
S
1
Posts: 34
Reputation: 512

Post » Wed Jul 02, 2014 12:37 pm

Bar.MaxLength (300 px in your example)
Bar.CurLength (the current length, max, 300 px, min 0 px, anything within those two values)

(Bar.CurLength / Bar.MaxLength) * 100
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306

Post » Wed Jul 02, 2014 12:56 pm

Thank you soooooooooo much. Works like a charm.
B
5
S
1
Posts: 34
Reputation: 512

Post » Wed Jul 02, 2014 1:55 pm

If you want however an indicator not starting from 0 (for exemple, if your bar min lenght would be 10)

You could use unlerp(minlenght, maxlenght, curlenght)*100 to get the percentage
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150


Return to How do I....?

Who is online

Users browsing this forum: kurtbal, Seruza and 8 guests