• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Camera Amateur Question (Viewport, appsurface etc.)

poliver

Member
I'm having an issue in my game where viewports work but are not showing. I suspect I'm doing something really daft but can't figure out what is wrong.

I'm seeing whole rooms on the screen instead of just the viewport but I know that viewports work cause parallax that refers to them scrolls accordingly and items that are supposed to be destroyed outside of view are getting destroyed outside of areas where viewport is supposed to be.

I have a global camera object and the code is like this

//CREATE EVENT
GML:
//DISABLE APPLICATION SURFACE
application_surface_draw_enable(false);

//SET FULLSCREEN
window_set_fullscreen(true);

//SET GAME WINDOW PARAMETERS
gameWidth  = 416;
gameHeight = 240;

//GET MONITOR PARAMETERS
monitorWidth  = display_get_width();
monitorHeight = display_get_height();

//CHECK HOW MANY TIMES THE GAME WILL FIT INTO MONITOR
maxWidthMultiplier  = monitorWidth  div gameWidth;
maxHeightMultiplier = monitorHeight div gameHeight;
maxSizeMultiplier   = min(maxWidthMultiplier, maxHeightMultiplier);

//FIND THE OFFSET AMOUNT TO CENTER THE SURFACE
xOffset = (monitorWidth  - gameWidth  * maxSizeMultiplier) / 2;
yOffset = (monitorHeight - gameHeight * maxSizeMultiplier) / 2;

//RESIZE SURFACE
surface_resize(application_surface, gameWidth * maxSizeMultiplier, gameHeight * maxSizeMultiplier);
//POST DRAW
GML:
//DRAW THE APPLICATION SURFACE
if (window_get_fullscreen()) {
    draw_surface_ext(application_surface, xOffset, yOffset, 1, 1, 0, c_white, 1);
}
else {
    draw_surface_ext(application_surface, 0, 0, 1, 1, 0, c_white, 1);
}
Theres also some code in the step event for camera to follow player which does nothing as I'm seeing the whole room ATM

GML:
//CHECK FOR RESIZE
if (window_get_fullscreen()) {
    surface_resize(application_surface,  gameWidth * maxSizeMultiplier, gameHeight * maxSizeMultiplier);
    camera_set_view_size(view_camera[0], gameWidth, gameHeight);
}
else {
    surface_resize(application_surface,  gameWidth, gameHeight);
    camera_set_view_size(view_camera[0], gameWidth, gameHeight);
}

if (instance_exists(objCharacter)) {
  
        var _x = clamp(objCharacter.x - gameWidth/2, 0,  room_width - gameWidth);
        var _y = clamp(objCharacter.y - gameHeight/2, 0, room_height - gameHeight);
  
        var _cur_x = camera_get_view_x(view_camera[0]);
        var _cur_y = camera_get_view_y(view_camera[0]);
  
        var _spd = 1;
        camera_set_view_pos(
            view_camera[0],
            lerp(_cur_x, _x, _spd),
            lerp(_cur_y, _y, _spd)
        );
        }
 
Top