0 Favourites

# Filling a bar using a quadratic formula

• 4 posts
• Hi guys, I got a question :)

I want the user to fill in a number (e.g. 6). Let's say the maximum is 20. Then I want a bar to be filled from it's current 'fillness' (how far the bar is filled at that moment) till 30% (6/20*100). I didn't want this to happen in one tick, instead, I wanted it too fill slowly. Starting with a high fill-speed, ending with a slow fill-speed (or 0).

No matter how big the distance between the current 'fillness' and the target, it should always happen in 150 ticks, no less and no more.

I thought about using the formula ax^2+c with a > 0 (not realizing this would make the fill-speed start slow and end fast). Because <a> would depend on it's current 'fillness' and target I set <a> to ((Target- current value)/(MAXT^2)) where MAXT is a constant, it should reach the target MAXT ticks further (from the moment of starting). I've set MAXT to 150 ticks.

((Target-current value)/(MAXT^2))

because

target = a*MAXT^2+current value (current as in at the moment of starting to move)

a*MAXT^2+current value = target

a*MAXT = target - current value

a = ((Target-current value)/(MAXT^2))

Then, MAXT ticks after the moment of starting to fill I set a sprite which is the fill-color its width to a*(t^2)+c

This works fine, except that it starts filling with a high speed and becomes slower when it reaches its target.

So how do I make it start fast and end slow?

I tried several things which all didn't work as I want it too. Have you guys got any ideas?

Sorry for the terrible vocab (fillness ._.)

• Sorry I won't to help you with the math because I suck at it ;)

But you can try that link as a neat alternative:

EaseTween

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• You might also try lerp:

lerp(a, b, x) Linear interpolation of a to b by x. Calculates a + x * (b - a)

This should give you the boost you're looking for at the start.

• You might also try lerp:

https://www.scirra.com/manual/126/system-expressions

lerp(a, b, x) Linear interpolation of a to b by x. Calculates a + x * (b - a)

This should give you the boost you're looking for at the start.

Thank you <img src="smileys/smiley1.gif" border="0" align="middle" />.

• 4 posts