parallax background on the y axis

A. DeVivo

Member
Hey all!
First time posting! Fairly new to GM2 but learning. In order to create depth on an island level, I'd like the horizon level of the ocean background layer to somewhat follow the player/ be fixed to the camera as the player/camera descend the y axis. I've been toying with lerp to do this, with the code
Code:
var layer_id1 = layer_get_id("Background_0")

layer_y(layer_id1, lerp(0,camera_get_view_y(view_camera[0]),.3));
however, this only makes it track a little bit. When I try to increase the last variable (.3 in the example code), I get a crazy shadowing multiplying effect that ain't great.

So what I'm wondering is how to (a) make the horizon following my player (ideally increasing/decreasing slightly depending on the y value, but generally tracking the player) and (b) how do I then stop the horizon from tracking the player once it is above a certain y axis (because it wouldn't make sense for the ocean to follow the player up to the top of the mountain).

I've provided some pictures to illustrate what I'm looking for. I'm currently toying with using both a tile background and one solid sprite that is smaller than the x/y of the room, so I'm flexible. I could also separate the ocean and sky into two separate sprites if necessary. This may be a bit out of my skillset at the moment, so I'd love some help. Particularly since there isn't a ton of information abt this for GM2. Thank you!!

sample1 (1).png sample2 (1).png sample3 (1).png
 
Last edited:

Ting_Thing

Member
Personally, I don't use lerp for my parallax scrolling.

I find it simpler to do something like this:
layer_y(layer_id1,camera_get_view_y(view_camera[0]/2)+50)

In the above example, 2 will put the background at half speed of the view, and 50 is the starting offset. Try that. I think it will work for you.
 

Simon Gust

Member
Since you know what the minimum (highest sea level) should be, instead of
Code:
layer_y(layer_id1, lerp(0,camera_get_view_y(view_camera[0]),0.3));
you can replace the 0 with the minimum level
Code:
min_sea_level = 200;
layer_y(layer_id1, lerp(min_sea_level, camera_get_view_y(view_camera[0]), 0.3));
 

A. DeVivo

Member
Thanks all! Ting_Thing- for some reason the non-lerp formula didn't do anything for me, but it's hard to say why. Simon Gust's method worked to achieve the desired affect, though I tinkered with it and got this clumsy thing:
Code:
min_sea_level = -5000;
layer_y(layer_id1, lerp(min_sea_level, camera_get_view_y(view_camera[0]), 0.868));
But now I'm wondering how I can get the ocean horizon to not follow the player as it jumps (ascends on the y axis) or moves upward past a certain point. I assume an "if" statement would work, though I am not sure the right way to phrase it. Like, if the player is ascending the y axis it remains static (or even moves away from it slightly), and if the player ascends above a certain y variable the horizon becomes fixed?

Right now the ocean is following the player around all the time, which I only want at a certain altitude and only when the player is descending, not jumping upwards.

Thanks again!
 
Last edited:

A. DeVivo

Member
As far as I can figure it out, it'd look something like this:
Code:
if (instance_exists(obj_player))
{
    if ((obj_player.bbox_bottom) > min_sea_level) || (obj_preem.spacebar) blee doo blah;
    else
layer_y(layer_id1, lerp(min_sea_level, camera_get_view_y(view_camera[0]), 0.868));
}
[CODE]

I basically need to know how to order it to stay put, I think? And how to tell it that the obj)player.bbox_bottom > min_sea_level) is in regards to the y axis? Again, not super confident in my coding abilities yet.
 
Last edited:

A. DeVivo

Member
Hey all,

This is about as far as I've gotten- still pretty lost. Any takers? Thanks for all the help thusfar.
Code:
if (instance_exists(obj_player))
{
    if (obj_player.key_jump) CODE TO INSTRUCT THE LAYER NOT TO MOVE
    else
    layer_y(layer_id1, lerp(min_sea_level, camera_get_view_y(view_camera[0]), 0.868));
}
A.
 
Last edited:
Top