Parallax scrolling

Hi,

I tried to answer an old thread about this, but I couldn’t see it on the list here, so instead I’m just pasting it in here so people can see it (sorry about that if there is any restrictions on doing this).

Currently I have a base foreground layer, base layer and a background layer, which are all working quite well. The foreground is used for the GUI, so this is static and is not supposed to move. That’s easy enough. The base is where the character is on, so here I have the camera following him around. That’s also in order. The background is just some skies which also are static.

However, I would love to have some more backgrounds that are moving slowly relative to the character. Like for example some mountains or something like that. And some kind of foreground that is also moving relative to the character, only faster, to get more depth.

It’s probably asking too much to get a tutorial about it, but if somebody who has managed to get this looking good I would appreciate some hints about it

On my base layer I’m centering the camera on a object that is following the playable character, but is slightly slower, to not have the character stuck in the dead center of the screen. Is it for example recommended to do something similar on the other layers?

Update: I think I found a way, at least for the foreground. Maybe I’ll be able to do something similar to the background too.

Here is an example :Parallax example.zip (1.6 MB)

In fact, you just have to create some layers used for the backgrounds, and put the different backgrounds on it.
Then, instead of centering the camera of these layers on the object to follow ( let’s call it MyObjectToFollow ), just put the X position of the camera of these layers to MyObjectToFollow.X()*0.25 for example ( and the same thing for Y if needed ).
The 0.25 factor i’ve used here tells that the background will follow MyObjectToFollow 4 times slower than usual ( 1/0.25 = 4 ). You can use others factors for the others backgrounds ( See my example ).

( I’ve used a more recent version of GD to create the example, don’t be worried by the warning displayed when you open the game :slight_smile: )

1 Like

This is fantastic! I hope you didn’t make all this just for me? :stuck_out_tongue:

Very much appreciated :slight_smile:

This may be a shot in the dark, but I was wondering if someone could point me in the right direction in regards to using parallax scrolling when you don’t move your avatar using the keyboard, but rather only with the mouse?

Currently I’m only using an action like “Move object to MouseX,MouseY with a force of x pixels” to control my avatar (and this can in any direction, not only on the X axis), so I’m thinking I would need something like a check of direction/speed of the avatar in order to move the cameraobject on the different layers around, but I’m a bit stuck.

Any thoughts?

I’m sorry. I realize now that you actually answered this, 4ian. The trick was of course to use both the X and the Y values for the different layers :slight_smile:

Yes, the example is based on the position of an object called “CameraObject”: Just put this object at a specific position ( For example, the mouse position ) and the background will be updated. :slight_smile:

Okay, for some reason I cannot extract a single .zip file from this site (yes I have the software for zips but these I cannot open for some reason).

So I have finally got my character moving properly and solid objects behaving nicely and now I would like to scroll the game in any direction (it is a top down) but I cannot find enough detailed info on the various options to put it all together. Scrolling in the Wiki is no help and there are many times that items like MyObject.X are not even explained in laymans details. I don’t mind the trial and error, is all good, but I feel I am struggling with this one.

I used a variable and set the camera to center on the player but that is not working. I like the idea of MyObject.x()*0.25 but I have no idea where to input this, or how, as all of the places I have looked do not give me anything that looks like the examples. Also, is there a way to post the code here to show what I am working with?

It seems that I need to make and place an object called Camera. From what I see in the forums the camera is not necessarily an automatic entity. Is this correct?

Would have been better to start a new topic than revive a >1 year old one… :unamused:

Anyway,

The camera already exists. You can change its position with Layers and cameras - Camera center x position (there is also a y position of course). For example, if you want an arrow on the right that lets you scroll to the right.
Conditions

Cursor is on arrow_right
Button left is clicked
Timer scrolltime > 0.15s 

Actions

Do +256 to camera x position
reset timer scrolltime

That’s the first time on any forum I have been told that, usually everyone is all jacked up about new topics, LOL. Anyway I do appreciate the feedback, I have been searching and trying ideas until I am just about bald.

Honestly I never looked at the date of the original post. I typed certain keywords in on several different searches in Wiki and Forum and the same handful of topics came up. This one seemed to be talking more closely about what I was after so I chose it in lieu of starting a new topic. I love new topics as it makes for a more well rounded board concerning precise issues but I was unsure of how to approach this here. I will not hesitate to do so in the future.

Thanks again Mats.

Please don’t post on 8 year old threads. Start a new thread instead.

And that is a 10 year old post you’re responding to, before GDevelop 5 existed. As such, the file will not work with GDevelop 5.