SOLVED Creating object that zoom automatically when created

Telorr

Member
Hi everyone!
I'm a newbie here, so I need your help

I want to make object that when I created it (call it oZoomIn and oZoomOut), it will zoom in automatically (oZoomIn) and zoom out automatically (oZoomOut).
I don't have any idea to do it, because I don't understand about camera zooming yet.
My app native screen resolution is HD (1280x720p). I want that oZoomIn will zoom in to the center of the screen until the screen resolution is 960x540p.
And I want that oZoomOut will zoom out from the center of the screen. From 1280x720p to 1600x900p.

Can you please help me? I can't make them both, Thanks!
 
Last edited:

Yal

šŸ§ *penguin noises*
GMC Elder
The easiest way probably is to make the camera view region bigger (increase its width and height) each step, you could have a width_start and width_end variable (1280 and 1600 respectively for ZoomOut, the reverse for ZoomIn) and then interpolate between them:
GML:
s += 0.01;//Set to 0 in create event. Adding 0.01 each step means the zoom takes 100 steps to complete.
w = lerp(w_start,w_end,s);
h = lerp(h_start,h_end,s);
camera_set_view_size(view_camera[0],w,h);
if(s >= 1){
  instance_destroy();
}
(as you can see, you'd obviously have separate start/end variables for height too)
 

Telorr

Member
Thanks, It's work smoothly..
But, my ZoomIn object is zooms to the top left of the screen, not to the middle of the screen.

This is my oZoomIn create event:
GML:
s = 0;
w_start = 1280;
w_end = 960;
h_start = 720;
h_end = 540;
view_enabled = true;
view_visible[0] = true;
view_camera[0] = camera_create_view(0, 0, w_start, h_start);
Can you help me again?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Move the camera's x position left with half the width change (if the width got wider, it moves left, if it got narrower, it moves right):

GML:
///Update the step event code from last time like this

//Get old size
ow = camera_get_view_width(view_camera[0])
oh = camera_get_view_height(view_camera[0])

//Zoom
s += 0.01;//Set to 0 in create event. Adding 0.01 each step means the zoom takes 100 steps to complete.
w = lerp(w_start,w_end,s);
h = lerp(h_start,h_end,s);
camera_set_view_size(view_camera[0],w,h);
if(s >= 1){
  instance_destroy();
}

//Shift camera
camera_set_view_pos(view_camera[0],camera_get_view_x[0] - 0.5*(w - ow),camera_get_view_y[0] - 0.5*(h - oh))
 

Telorr

Member
I changed the camera shift line a bit (because I encountered an error), from this:
//Shift camera camera_set_view_pos(view_camera[0],camera_get_view_x[0] - 0.5*(w - ow),camera_get_view_y[0] - 0.5*(h - oh))
To this:
GML:
camera_set_view_pos(view_camera[0], camera_get_view_x(view_camera[0]) - 0.5*(w - ow), camera_get_view_y(view_camera[0]) - 0.5*(h - oh))
Now, it's work perfectly
Thank you very much for your help!
 
Top