GameMaker Parallax Scrolling Backgrounds

Instead of creating a new thread I thought I'd just add to this one.

MOD EDIT: Posts have been split from the linked topic above into their own topic.



My parallax stopped working when I changed camera.

My parallax code is in it's own object in the step event:

GML:
var cam_x = camera_get_view_x(view_camera[0]);
var cam_y = camera_get_view_y(view_camera[0]);

layer_x("Parallax_01", cam_x * 0.25);
layer_y("Parallax_01", cam_y * 0.25);
It worked fine when I used the regular camera and object following my player object, but I recently switch to Spaldings "Smooth Camera Tutorial" and it stopped working. I can't seem to figure out what I should change for it to work.

Spalding style camera object:

Create
GML:
camera = camera_create();

var vm = matrix_build_lookat(x, y, -10, x, y, 0, 0,1,0);
var pm = matrix_build_projection_ortho(640, 360, 1, 10000);

camera_set_view_mat(camera, vm);
camera_set_proj_mat(camera, pm);

view_camera[0] = camera;

follow = obj_player;

xTo = x;
yTo = y;
Step:

GML:
x += (xTo - x)/5;
y += (yTo - y)/5;

if (follow != noone)
{
    xTo = follow.x;
    yTo = follow.y - 50;
}

var vm = matrix_build_lookat(x, y, -10, x, y, 0, 0, 1, 0);
camera_set_view_mat(camera, vm);
 
Last edited by a moderator:

Yal

šŸ§ *penguin noises*
GMC Elder
Hi guys.

Sorry for the noob question, I have searched google and these forums up and down and can't seem to figure out how to get parallax scrolling backgrounds in GMS2.

That being, a "further" background layer (sky, mountains, what have you) moving slower than "closer" background layers.

Anybody know the answer to this?

I found 1 post I think but it was incomplete and they never got back to explaining how they did it.

Also, I am using the DND tools. But I assume I can add code anyway so I don't think there should be any problem if you guys only know in code, I'll just drop it anyway. (I mean, I ended up having half of the game I am making "code-like" anyway by this point).

Thank you in advance.
The hard part here is that "Moving slower" with respect to the view means that you want a higher speed with respect to the room. So if you have 3 background layers, the furthest background should be repositioned by 0.75*view coordinates, the next one with 0.5*view coordinates, and the nearest with 0.25*view coordinates.

When I say view coordinates, I mean I just set the background layers' position to a multiplier x the view coordinates - simple to implement, and the background stops moving when the view reaches the edge of the screen because the view is already clamped. Use camera_get_view_x(view_camera[view_current]) and camera_get_view_y(view_camera[view_current]) to read these.
 
Top