• 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 Smooth Parallax Background

Plubu

Member
Hello everyone,

I've seen videos of how to code a Parallax Backgrounds, it worked for me but it's not smooth, when the player stops or just starts moving, the background ike cuts off or something, it's not smooth.

This is my Camera object:
GML:
//Create

//Display Settings
IdealWidth = 1920;
IdealHeight = 1080;

Aspect_Ratio = display_get_width() / display_get_height();

IdealWidth = round(IdealHeight * Aspect_Ratio);

//Check for Odd Numbers
if (IdealWidth & 1)
{
    IdealWidth += 1;
}

//Build a camera at (0,0), with size 640x480, 0 degrees of angle, no target instance, instant-jumping hspeed and vspeed, with a 32 pixel border
camera = camera_create_view(0, 0, IdealWidth, IdealHeight, 0, -1, -1, -1, 32, 32);

for(var i=1; i<= room_last; i++)
{
    if (room_exists(i))
    {
        room_set_camera(i, 0, camera);
        room_set_viewport(i,0,true, IdealWidth, IdealHeight, IdealWidth, IdealHeight);
 
    }
}

surface_resize(application_surface, IdealWidth, IdealHeight);
window_set_size(IdealWidth, IdealHeight);
This is where I can change the speed of the parallax background:
GML:
//Step

//Backgrounds

var _cam_x = camera_get_view_x(view_camera[0]) ;
layer_x("BG", _cam_x * 0.3); // Change the background layer name to whatever you use in the room editor
This is where the camera follows the player, in the Player's object:
GML:
//End Step

#region Camera Folowing The Player
    HalfWidth = camera_get_view_width(view_camera[0]) / 2;
    HalfHeight = camera_get_view_height(view_camera[0]) / 2;

    camera_set_view_pos(view_camera[0], x - HalfWidth, y - HalfHeight);
#endregion
I think this is all the things that are related to the camera.

Many thanks.
 

TrunX

Member
If its pixel art and the camera moves very slow, its natural that the different layers will move uneven one px at a time (at different times).
One solution could be to not move the camera until it reached minimum movement speed of 1.
 

Plubu

Member
If its pixel art and the camera moves very slow, its natural that the different layers will move uneven one px at a time (at different times).
One solution could be to not move the camera until it reached minimum movement speed of 1.
Forgot to check this post, but had it fixed now.

Many thanks for the response!
 
Top