How To Make Distance Based Zoom in One Line

2

Attached Files

The following files have been attached to this tutorial:

.capx

distance-based-zoom.capx

Download now 173.71 KB

Stats

2,499 visits, 3,569 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 17 Aug, 2015. Last updated 19 Feb, 2019

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
  • 1 Comments

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