Background Layer Horizontal Speed Issue

D

Dario8676

Guest
Hi all, I haven't worked very much with background layer speed manipulation in gamemaker when it comes to the concept of parallex scrolling and moving backgrounds, so I was hoping for some help.

In my room I have a background layer for clouds that I set a Horizontal Speed of -.5 in the layer properties. I also have a few other background layers for mountains and a moon that I've created a parallex effect on.

The issue is that the clouds do scroll on their own at -.5 but once the camera moves with the player, the cloud moves -.5 plus the characters speed thus ruining the effect.

In the camera step event I was testing the following:

layer_x(bgCloud1, x);

This freezes the cloud background to move along with the camera x, but then magically the -.5 Horizontal speed no longer works and the cloud doesn't move on its own anymore. Any ideas?
 
D

Dario8676

Guest
Use your own variable to move the clouds...

cloud_scroll+=0.5;
layer_x(bgCloud1, x+cloud_scroll);
That worked, thank you! However one caveat. Cloud_scroll never gets reset so it will keep heading towards infinity. The clouds are horizontally tiled so this is working great, but how do you reset the counter without breaking the clouds
 

obscene

Member
Here are two ways...

cloud_scroll = cloud_scroll mod sprite_get_width(bgCloud1);

or

var spw=sprite_get_width(bgCloud1);
if (cloud_scroll >= spw) cloud_scroll-=spw;
 
D

Dario8676

Guest
Here are two ways...

cloud_scroll = cloud_scroll mod sprite_get_width(bgCloud1);

or

var spw=sprite_get_width(bgCloud1);
if (cloud_scroll >= spw) cloud_scroll-=spw;
I will give it a shot, thank you
 
D

Dario8676

Guest
Use your own variable to move the clouds...

cloud_scroll+=0.5;
layer_x(bgCloud1, x+cloud_scroll);
Hi obscene so it wor
Use your own variable to move the clouds...

cloud_scroll+=0.5;
layer_x(bgCloud1, x+cloud_scroll);
So this works pretty well, but when the camera moves it effects the speed of the clouds, but they should scroll independently
 
D

Dario8676

Guest
Use your own variable to move the clouds...

cloud_scroll+=0.5;
layer_x(bgCloud1, x+cloud_scroll);
So I wanted to reopen this because I'm still having a slight issue. So this method works great while standing still but the second the camera moves along with the player the clouds move along with the camera as well causing the clouds to move an an offseted value of camera.x.

How do i make the backgrounds clouds relative to the viewport and not the camera.
 
Top