Zoom Out Distorting Sprites

I've started a project of a local multiplayer shooter, where the cameras will work like this:
- 1 player : the camera will only focus the player , without zoom
- 2 player: the camera will calculate a zoom and it will add to the camera size

but i have a problem, when the camera add the zoom out the sprites start adding pixel and stretching, losing the aspect ratio

#macros
GAMEWIDTH = 640;
GAMEHEIGHT = 360;


heres the code:

Game object -> i use to control the game in general
//create
GML:
windowscale = 2;

window_set_size(GAMEWIDTH*windowscale,GAMEHEIGHT*windowscale);
display_set_gui_size(GAMEWIDTH*windowscale,GAMEHEIGHT*windowscale);
alarm[0] = 1;

surface_resize(application_surface,GAMEWIDTH*windowscale,GAMEHEIGHT*windowscale);

oCAMERA object -> the actual camera code
//Create
GML:
following = oparPlayer;
zoom = 2;
spd = 0.1; //the speed of interpolation
//Step
GML:
gameW = GAMEWIDTH / 2 * zoom;
gameH = GAMEHEIGHT / 2 * zoom;

camera_set_view_size(CAM, gameW, gameH);

var player_num = instance_number(oparPlayer);
var players = ds_grid_create(1,1);
ds_grid_resize(players,1,player_num);

var i = 0;
with(oparPlayer){
    players[# 0,i] = id;
    i++
}

switch(player_num){
   case 1 : //single player
        if(instance_exists(following)){
            var xx = clamp(following.x - gameW/2, 0, room_width - gameW);
            var yy = clamp(following.y - gameH/2, 0, room_height - gameH);

            var cx = camera_get_view_x(CAM);
            var cy = camera_get_view_y(CAM);   

            camera_set_view_pos(CAM,
                             lerp(cx,xx,spd),
                             lerp(cy,yy,spd) );
                    

        }

    break;

    case 2: //2 players

       var multi_xx = mean(players[# 0,0].x,players[# 0,1].x);
       var multi_yy = mean(players[# 0,0].y,players[# 0,1].y);


       var xx1 = clamp(multi_xx - gameW/2, 0, room_width - gameW);
       var yy1 = clamp(multi_yy - gameH/2, 0, room_height - gameH);

       var distance_x = abs(players[# 0,0].x - players[# 0,1].x);
       var distance_y = abs(players[# 0,0].y - players[# 0,1].y);

       zoom = clamp(lerp(zoom, sqrt(sqr(distance_x) + sqr(distance_y) ) / 100, spd- 0.05), 3, 4)


        var cx = camera_get_view_x(CAM);
        var cy = camera_get_view_y(CAM);


        camera_set_view_pos(CAM,
                            lerp(cx,xx1,spd),
                            lerp(cy,yy1,spd) );

    break;

    }
My inspiration to the camera code was the camera of the duck game.


here is when the zoom is 1:
View attachment 29456

and when zoom is 4:
View attachment 29457

im just showing this zoom level, but almost any zoom it starts to add more pixels
 

sp202

Member
Distortion is expected if you zoom out too far because the game has to somehow represent the same sprite with less pixels, so depending on the sampling algorithm you'll end up with it looking non-uniformly scaled.
 
Distortion is expected if you zoom out too far because the game has to somehow represent the same sprite with less pixels, so depending on the sampling algorithm you'll end up with it looking non-uniformly scaled.
So even if i use my pixel perfect camera, it will try to emulate some pixels?

As i know when there is only one player at the room the pixel perfect camera works very well, because it doesn't need to calculate the zoom
 
Top