How To Make Distance Based Zoom in One Line

Attached Files

The following files have been attached to this tutorial:

.capx

distance-based-zoom.capx

Download now 173.71 KB

Stats

1,205 visits, 1,883 views

Translations

This tutorial hasn't been translated.

Tools

HOW ?

The original scale of construct layout is 1.

So when you want to zoom it, you need to modify the scale. The bigger the value, the bigger zoom you get.

To dynamically zoom our layout, use the following formula for every tick :

    LayoutScale = lerp(current_scale,desired_scale,required_time_to_zoom)

Example 1

Say that I have two characters which can move on their own. To zoom the camera based on on their distance, add this event :

Run the layout, and you can see that the layout is zooming smoothly.

WHY?

Just like I said before, we need to modify LayoutScale. You got it.

To get the correct scale, we need to divide WindowHeight (for landscape view) or WindowWidth (for portrait view) with player distance.

Example 2

Window Size = 640x480

Current layout scale = 1

Current distance = 300

What is the scale if the distance is now 600?

Answer :

Scale = 480/600 --> 0.8

NEXT THING TO DO

Limit the scalling to get more control.

For instance, do it only when character distance is longer than 300, and less than 700.

Have fun!

if you like this tutorial, please like my

facebook fanpage

.CAPX

distance-based-zoom.capx

Download now 173.71 KB
  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!