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

Help making background follow the camera

Lunarium

Member
Hello, i'm working on a platformer and i'm trying to make it so that the background follows the camera while it's moving, so that in the game it looks like it's staying still. I already searched for tutorials on this but i didn't find anything exactly like what i was looking for.
 

FoxyOfJungle

Kazan Games
You can use a background layer and then move it to the camera position:

GML:
// get camera horizontal position
var cam_x = camera_get_view_x(view_camera[0]);

// get layer id
var _layer_id = layer_get_id("layer_name");

// move layer with the camera x position
layer_x(_layer_id, cam_x);
For better performance, you can get the layer id in the Create Event and use the variable later in the Step Event.
 
D

Deleted member 13992

Guest
You can use layer_x and layer_y to offset the background layer as you see fit, including making it follow the camera! Definitely the simplest solution.


EDIT: Whoops, beaten by a minute.
 
Top