GMS 2 Choppy Parallax Scrolling

Q

Quinton LeBlanc

Guest
I've searched high and low for a solution to this issue, and I'm not experienced enough to tinker with things like this myself. I am trying to make the background scroll by to give my game more of a 3D effect. But when my character moves, or stops moving, the elements of the background move choppily. Even the sun, which is supposed to stay static is stuttering for absolutely no reason whatsoever. It SHOULD work.
Here is the code inside of my camera objects create event

Code:
///Camera Creation
global.camera = camera_create_view(x, y, o_global_displaymanager.ideal_width, o_global_displaymanager.ideal_height, 0, self, -1, -1, 275, 275);
view_camera[0] = global.camera
for (var i = 1; i <= room_last; i++) {
    if (room_exists(i)) {
        room_set_camera(i,0,global.camera)
        room_set_viewport(i,0,true,0,0,o_global_displaymanager.ideal_width,o_global_displaymanager.ideal_height)
        room_set_view_enabled(i,true);
    }
}
essentially creating the camera. As you can see I am using Pixelated Popes display manager to essentially scale my game up to multiple resolutions. Resolution isn't the issue here as I have the game running at 2x resolution and am still getting this issue.

here is the code inside my camera's step event

Code:
///Smooth Camera
x += (o_plyr.x - x) * .1;
y += (o_plyr.y - y) * .1;
This smooths the cameras movement, so the cameras starting and stopping is not instantaneous.

This is the code inside of my camera objects end step event

Code:
/// Parallax Backgrounds
// Define layer IDs
var layer_id1 = layer_get_id("back");
var layer_id2 = layer_get_id("mid");
var layer_id3 = layer_get_id("front");
    layer_x (layer_id1, lerp(0, camera_get_view_x(view_camera[0]), 1));
    layer_x (layer_id2, lerp(0, camera_get_view_x(view_camera[0]), .75));
    layer_x (layer_id3, lerp(0, camera_get_view_x(view_camera[0]), .25));
Here is the choppiness in action. look at how it jumps around, especially when my character and the camera slows to a stop.
 

Slyddar

Member
The camera is moving the smallest amount it can, which essentially becomes 1 pixel at a time at the end of the smoothing.

Some options are you can either look into subpixel movement, I believe Pixelated Pope has a tutorial on that with camera movement.
You can change the smoothness to be less smooth so the last few pixel movements are not so obvious.
You can change the camera/view resolution to be larger so the pixels are smaller and the movement will not show as being so obvious.
 
Q

Quinton LeBlanc

Guest
The camera is moving the smallest amount it can, which essentially becomes 1 pixel at a time at the end of the smoothing.

Some options are you can either look into subpixel movement, I believe Pixelated Pope has a tutorial on that with camera movement.
You can change the smoothness to be less smooth so the last few pixel movements are not so obvious.
You can change the camera/view resolution to be larger so the pixels are smaller and the movement will not show as being so obvious.
I am currently using Pixelated Popes display manager.
 

samspade

Member
I am currently using Pixelated Popes display manager.
I can't tell for sure, but uou probably need to have something that zero's out the movement. The camera is likely to go past the x, then go past in the other direction, then go past again in the first and so on. Something like this might work:

Code:
var hsp = (o_plyr.x - x) * .1;
var vsp = (o_plyr.y - y) * .1;

if (abs(hsp) > 0.5) {
     x += hsp;
}

if (abs(vsp) > 0.5) {
     y += vsp;
}
Edit: never mind. Re watching the video I think it might be a different problem. The above code may still help though. I would simply increase the minimum distance the camera can move. I think the last few pixels are just jittery because x is slowly getting added to over several frames and then moving a single pixel, and then repeating.
 
1. You can try and find numbers that go slightly better together than 1.0 | 0.75 | 0.25:
Just for testing, let a key or button change those values dynamically and see what works best.
Sounds stupid, but can make quite a difference

2. Take control on how layer_x is rounded. Test what looks best: ceil, floor, round.

3. Change the tween of the camera-follow. The reason why it's getting so obvious is because you're lerping each step which means the movement gets really slow in the end and that's noticeable.

4. But even then it'll never be supersmooth unless you use "subpixels". But it rarely needs to be supersmooth. Owlboy i.e. looks gorgeous and afaik doesn't use subpixels. The parallax is a bit choppy, but not in a bothering way anymore.
 
Top