How do I get the parallex effect working with the smooth camera behaviour?

How do I…

Ive been struggling all day to get the parallax effect working in my game. I have followed all examples and each of them try it differently. Some use the events sheet and some use the parallax behaviour on the background object.

I have set the background on a separate layer and given it the parallax behaviour

I have also zoomed in the camera at the beginning of the scene and I have done this for both layers as can be seen from my very small event sheet

I have also used the smooth camera behaviour and the background jumps with the player, which is very strange.

What is the expected result

For the parallax effect to work using the provided behaviour. Also that the background only scrolls along the x-axis and does not follow the player when player jumps.

What is the actual result

The background is cut out for some reason and when the player jumps, the background layer follows it as well.

Here is the editor screenshot:

Related screenshots

Apparently Im only allowed one screenshot per post. I’ll try to add other screenshots in reply if it will allow me

And here is what it looks like in the game

Event sheet below:

I can show you how I do it.

The player object has the smooth camera behaviour. You can use the settings for that to choose if the camera follows your character on X and Y, or just X.

image

At the beginning of the scene I centre the camera on the player object. You don’t need to set this every frame.

And then I use this event for my tiled parallax background:

image

It runs every frame (no conditions).

The parallax tile is on its own layer.

That’s it.

My game has a fixed width (its not an endless runner). In the scene editor, I drag out the background parallax tile to be as wide as my scene. I don’t use an event to set its width dynamically, but I tried a quick experiment and got it to size properly using this, though other users might suggest a better/different way. Using camera width also seemed to work.

image

(and I’ve just realised I’ve been spelling ‘parallax’ wrong all these months :upside_down_face:)

1 Like

Thanks for the reply. Thats very helpful.

The parallax effect can only be added on tiled images and not on sprite images. But I cant seem to adjust the height of the tiled images because I then get this repetition (which I think is the intended effect)

Do you resize your images to match the height of the game screen before importing them into GDevelop?

You’re welcome :slight_smile:. Yes, my tile is as high as the scene, so it’s not tiling vertically (although it would if I made the image taller in GDevelop, but it would look like your screenshot, which is the intended behaviour of the tile). Some of my future scenes will be taller than 1080, but I think I’ll probably still only have the tile move on the X axis. Otherwise I’d need a very tall image.

I have foreground parallax too. It moves a little faster than the base layer and is in front of it. It uses sprites and not tiles. I do that by targeting the layer. The only things on that layer are the out-of-focus grass sprites.

image

I lay out all the objects in the scene editor and I don’t use events to create them.

So you end up with 3 layers moving at different speeds, creating a nice feeling of depth.

1 Like