JeanSwamp
Member
I'm trying to make a zoom for my player on a sidescrolling platformer. Currently everything works flawlessly expect when switching from zooming in to out, since the pos is relative to the top left corner and not the center, there's a quick repositioning on switch that looks very ugly.
I've tried a lot of things and I can't figure it out.. Here's the current code:
Like I said everything works as I want, I'm just missing a way to fix the repositioning. I've seen a lot of tutorials about centering the camera with a shift values, but I don't want the camera to be "centered" in the middle of the view, but on the player.
Hopefully someone can help me out! Thanks
I've tried a lot of things and I can't figure it out.. Here's the current code:
Code:
follow = oPlayer;
xTo = follow.x;
yTo = follow.y;
x = lerp(x,xTo,0.2);
y = lerp(y,yTo,0.2);
zoom_level = 0.5;
var view_w = camera_get_view_width(view_camera[0]);
var view_h = camera_get_view_height(view_camera[0]);
zoom_w = lerp(view_w, zoom_level * default_zoom_width, rate);
zoom_h = lerp(view_h, zoom_level * default_zoom_height, rate);
zoom_x = view_w_half * zoom_level;
zoom_y = view_h_half * zoom_level;
camera_set_view_size(cam, zoom_w, zoom_h);
camera_set_view_pos(cam,x-zoom_x,y-zoom_y);
Hopefully someone can help me out! Thanks