Filling a bar using a quadratic formula

Get help using Construct 2

Post » Mon Feb 25, 2013 3:25 pm

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 ._.)Jasper2013-02-25 15:26:35
B
13
S
3
G
4
Posts: 35
Reputation: 3,358

Post » Mon Feb 25, 2013 4:59 pm

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:
EaseTweenlemo2013-02-25 17:00:05
B
20
S
5
G
8
Posts: 325
Reputation: 6,473

Post » Tue Feb 26, 2013 6:46 am

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.
B
7
Posts: 38
Reputation: 476

Post » Sat Mar 02, 2013 11:19 am

[QUOTE=Curious Mike] 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.[/QUOTE]
Thank you .
B
13
S
3
G
4
Posts: 35
Reputation: 3,358


Return to How do I....?

Who is online

Users browsing this forum: farfetchd83, mjj1990 and 3 guests