Slow and smooth display zoom.

For questions about using Classic.

Post » Tue Jul 07, 2009 6:24 pm

Hello again :)

I have new question.
When I press Space - display quickly zooms in. When I release the key - it quickly returns back.
How to make that when I press the key, it slowly and smoothly zooms in (for example 3 sec) and after releasing the key it slowly and smoothly zooms out (3 sec too).
This effect also was in 3D Driving tech demo.

Thanks.
B
3
S
2
G
3
Posts: 146
Reputation: 1,567

Post » Tue Jul 07, 2009 6:43 pm

In the driving demo the zoom is based on how fast the car is moving.

If you want to zoom over time, then you have to change the zoom amount over time.

If you want to zoom over the span of 3 seconds based on a key press like you posted then you can try something like this:

[code:3u9lo40g]
+ Key "Space" is down
+ System Compare: ZoomX less than 200
+ Every 30 milliseconds
-> Set zoom (ZoomX + 1, ZoomY + 1)

+ NOT Key "Space" is down
+ System Compare: ZoomX greater than 100
+ Every 30 milliseconds
-> Set zoom (ZoomX - 1, ZoomY - 1)
[/code:3u9lo40g]
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Jul 07, 2009 8:17 pm

Hello, deadeye.

Thank you. It works. :D
B
3
S
2
G
3
Posts: 146
Reputation: 1,567

Post » Wed Jul 08, 2009 12:15 am

Lerp its your friend.
[code:3g6pzche]MouseKeyboard: Key "Space" is down
> SystemSet Layer 1 zoom ratio to (lerp(200, LayerZoomX("Layer 1"), 0.0005^timedelta), lerp(200, LayerZoomY("Layer 1"),0.0005^timedelta))

MouseKeyboard: Key "Space" is not down
> SystemSet Layer 1 zoom ratio to (lerp(100, LayerZoomX("Layer 1"), 0.0005^timedelta), lerp(100, LayerZoomY("Layer 1"), 0.0005^timedelta))[/code:3g6pzche]

Or if your feeling frisky change the second event to an else.
[code:3g6pzche]System: Else
> SystemSet Layer 1 zoom ratio to (lerp(100, LayerZoomX("Layer 1"), 0.0005^timedelta), lerp(100, LayerZoomY("Layer 1"), 0.0005^timedelta))
[/code:3g6pzche]
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Wed Jul 08, 2009 9:21 am

Nice. If you wouldn't mind, a thread or a bit on the wiki about lerp uses would be really helpful I'd wager? It's very useful.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Wed Jul 08, 2009 11:21 am

I guess I could make a thread and example up.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Wed Jul 08, 2009 1:13 pm

What is lerp?
B
11
S
3
G
4
Posts: 622
Reputation: 3,186

Post » Wed Jul 08, 2009 1:19 pm

[quote="Sagal":3dlk98nk]What is lerp?[/quote:3dlk98nk]its Linear Interpolation
[code:3dlk98nk]lerp(a, b, x)[/code:3dlk98nk]So basicly you are putting a linear function vars in a,b,x and you find y in point x.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Wed Jul 08, 2009 4:59 pm

That's a slightly confusing way to describe it I think :P

lerp(a, b, x) = a + (b - a) * x

lerp gives you the value x% of the way from a to b. So if x is 0, it gives a, if x is 1 (100%), it gives b, and if x is 0.25 (25%), x gives the number 25% of the way from a to b, etc. For example:
lerp(60, 100, 0.25)
= 60 + (100 - 60) * 0.25
= 60 + 40 * 0.25
= 60 + 10
= 70, the number a quarter of the way from 60 to 100.

Lerp is incredibly handy if you get to know it well and is used all over many games (and several times inside Construct itself too).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Wed Jul 08, 2009 5:46 pm

ah ok thanks
B
11
S
3
G
4
Posts: 622
Reputation: 3,186

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest