GMS 2.3+ Parallax help!

Pikpik

Member
I watched this video on the subject, but I couldn't get it to work without using the smooth camera used in the video. I just want the camera to follow the player using the Object Following setting in the camera properties menu.

Edit: What I mean is, I need a camera object that follows the player closely instead and has the parallax working.
 
Last edited:

sivispacem

Member
You should watch these tutorials but understand they are not for GMS 2.3 (appear to still work)
(3 vids)
(1 vid)
 

sivispacem

Member
Since you may run into the same problem I am currently having, I am going to ask my question here instead of making another post:

I have followed the above tutorials (GML) as well as with Shaun's video
.
However, my backgrounds do not seem to be parallax-ing correctly.

obj_camera/Create
GML:
layer_rm_001_3 = layer_get_id("Layer_rm_001_3")
layer_rm_001_2 = layer_get_id("Layer_rm_001_2")
layer_rm_001_1 = layer_get_id("Layer_rm_001_1")
obj_camera/Step
GML:
/// @desc Camera and Parallax
//Follow Target
if(instance_exists(target))
{
    global.camera_x = target.x-(global.camera_width/2);
    global.camera_y = target.y-(global.camera_height/2);
    global.camera_x = clamp(global.camera_x, 0, room_width-global.camera_width);
    global.camera_y = clamp(global.camera_y, 0, room_height-global.camera_height);
}
camera_set_view_pos(view_camera[0], global.camera_x, global.camera_y);
//Parallax
if(instance_exists(layer_rm_001_3))
{
    layer_x(layer_rm_001_3, global.camera_x*0.98);
    layer_y(layer_rm_001_3, global.camera_y*0.98);
}

if(instance_exists(layer_rm_001_2))
{
    layer_x(layer_rm_001_2, global.camera_x*0.92);
    layer_y(layer_rm_001_2, global.camera_y*0.92);
}

if(instance_exists(layer_rm_001_1))
{
    layer_x(layer_rm_001_1, global.camera_x*0.86);
    layer_y(layer_rm_001_1, global.camera_y*0.86);
}
obj_camera/Room Start
GML:
global.camera_x = 0;
global.camera_y = 0;
target = obj_player_1;
global.camera_width = 1536;
global.camera_height = 768;

view_enabled = true;
view_visible[0] = true;

view_camera[0] = camera_create_view(0, 0, global.camera_width, global.camera_height, 0, obj_player_1, -1, -1, global.camera_width/2, global.camera_height/2);
camera_set_view_size(view_camera[0],global.camera_width, global.camera_height)

display_scale = 2
display_width = global.camera_width * display_scale;
display_height = global.camera_height * display_scale;

window_set_size(display_width,display_height);
surface_resize(application_surface,display_width,display_height)
display_set_gui_size(global.camera_width-20, global.camera_height-20);

alarm[9] = 1;
Everything about the camera works exactly how I want it. However, the background is static.
I have checked that all names / variables match.
The background sprites are tiled as per the tutorials.
 

sivispacem

Member
I watched both of the tutorials multiple times and I believe the problem is that I declared the
GML:
layer_rm_001_1 = layer_get_id("Layer_rm_001_1")
in the Create Event for the camera instead of declaring them in the Step Event.

GML:
layer_rm_001_2 = layer_get_id("Layer_rm_001_2");
layer_rm_001_1 = layer_get_id("Layer_rm_001_1");
if(layer_exists(layer_rm_001_2))
{
    layer_x(layer_rm_001_2, global.camera_x*0.9);
    layer_y(layer_rm_001_2, global.camera_y*0.9);
}

if(layer_exists(layer_rm_001_1))
{
    layer_x(layer_rm_001_1, global.camera_x*0.8);
    layer_y(layer_rm_001_1, global.camera_y*0.8);
}
 
Top