Slow and smooth display zoom.

This forum is currently in read-only mode.
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • 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.

  • 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:

    + 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]
  • Hello, deadeye.

    Thank you. It works.

  • Lerp its your friend.

    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.

    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]

  • 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.

  • I guess I could make a thread and example up.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What is lerp?

  • What is lerp?

    ts Linear Interpolation

    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.
  • That's a slightly confusing way to describe it I think

    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).

  • ah ok thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)