• 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] I want the BG parallax stop and stick its position on camera when player moves

Dunkelheit

Member
I have 3 backgrounds with parallax movement. I just want one of them stop moves and follows the camera movement the way that it look likes a static one.

# backgrounds:
1 - Clouds (this one is my problem);
2 - Far graves;
3 - Close graves;

Far and Close graves backgrounds are working just fine. The routine to make them moves are:

Code:
layer_x("BG_FarGraves", o_skeleton.x / 1.8);
layer_x("BG_CloseGraves", o_skeleton.x / 2.5);
o_skeleton object is the player.

The cloud background is automatically configured in the room. I set up it inside the room with these properties:

Horizontal Tile: checked;
Horizontal Speed: 0.05;


The current result I have is when the player is idle the clouds moves the way it should be, however, when the player moves the clouds moves way to fast on unrealistic way.

I want when player moves the clouds just stop moves or just keep moving the way it moves when player is idle. I'm trying to reproduce this scenario but I can't.

#attempts:
doesn't work like I want to
Code:
layer_hspeed("BG_Clouds", 0);
layer_x("BG_Clouds", layer_get_x("BG_Clouds"));
moves so fast like a crazy cat:
Code:
layer_hspeed("BG_Clouds", 0);
layer_x("BG_Clouds", camera_get_view_x(view_camera[0]));
If someone can help me out here, I'll appreciate it so much. Thanks and sorry about my english.

EDIT SOLUTION:

I created a camera object to handle camera and clouds background instead to make camera from room automatically follows the player:

P.S.: Camera snippet was based on Shaun camera snippet. Cloud parallax was by myself.

The cloud background remains with "Horizontal Tile" option checked on room settings also the same other parallax backgrounds.

Code:
#event create
cam = view_camera[0];
follow = o_skeleton;
view_w_half = camera_get_view_width(cam) / 2; //pode ser * 0.5
view_h_half = camera_get_view_height(cam) / 2 + 32; //pode ser * 0.5
xTo = xstart;
yTo = ystart;
lay_x = 0;

#event step
// You can write your code in this editor
if instance_exists(follow)
{
    xTo = follow.x;
    yTo = follow.y;
}

//atualiza a posição do objeto
x += (xTo - x);
y += (yTo - y);

x = clamp(x, view_w_half, room_width - view_w_half);
y = clamp(y, view_h_half, room_height - view_h_half);

//atualiza a posição da camera
camera_set_view_pos(cam, x - view_w_half, y - view_h_half);

/////////////////////
//cloud parallax
/////////////////////

lay_x += 0.05
layer_x("BG_Clouds", x + lay_x);
So, lay_x is always being incremented and layer_x function moves the background from left to right. To make it works I ignored layer_hspeed() function or "Horizontal Speed" properties on the room. Others backgrounds still remains using layer_hspeed() function.

The result: clouds backgrounds moves itself regardless the player movement. Other backgrounds moves accordingly each one with specific intensity following player movement.
 
Last edited:
Top