• 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!

Camera problem in GM2

B

Beggar Studios

Guest
Hey everyone,

I recently upgraded to Game Maker Studio 2 and I noticed there is a new camera system. So I'm trying to revamp my old code so it uses cameras instead of the old views, but I ran into a problem. There is this weird shaking effect when the camera follows the player that doesn't occurs when I'm using the old system. I made 2 gifs to demonstrate this and you can find the code below. Can someone help?

Code:
// Creation of the camera and binding it to a view

global.camera = camera_create_view(0, 0, 480, 270, 0, obj_view, -1, -1, 241, 136);
view_set_camera(0, global.camera);
Code:
// Code to make obj_view follow the player

if(obj_player.state == scr_move_state){
    var xdis = floor((obj_player.x - x)) * 0.1;
    var ydis = floor((obj_player.y - y)) * 0.1;
    
    if(xdis < 0.5 && xdis > 0){
        xdis = 0.5;
    }
    
    if(ydis < 0.5 && ydis > 0){
        ydis = 0.5;
    }
    
    if(xdis > -0.5 && xdis < 0){
        xdis = -0.5;
    }
    
    if(ydis > -0.5 && ydis < 0){
        ydis = -0.5;
    }

    x += xdis;
    y += ydis;
}
Code:
// Old code to make the view follow obj_view

// Since the upgrade GM depricated this code so now it looks weird like this

__view_set( e__VW.XView, 0, obj_view.x - __view_get( e__VW.WView, 0 )/2 );
__view_set( e__VW.YView, 0, obj_view.y - __view_get( e__VW.HView, 0 )/2 );
old system (smooth):

http://imgur.com/a/tMynQ

new system with camera (not smooth):

http://imgur.com/a/lIpTR
 

origamihero

Member
Hi! I've run into troubles like these as well. You can get this kind of shaky scrolling if:

  • Your character movement code is run after the scrolling code
  • Your character moves at a sub-pixel level (floating point numbers)
  • Your view moves at a sub-pixel level
If your scrolling code is already running after the player movement code, try setting the view to the exact player position as a test and check if that works well. If it does, the problem is likely something about the floating point numbers.
 
Top