Background looping

Hi Guys,
Please let me know how to loop a background in the game, I tried searching the same on the forum and found some examples but they are in .gdg format and I am unable to open it through GDevelop app. I am only able to open .json files in GDevelop.
so please help. also let me know how to open .gdg file in GDevelop for future reference.

I fixed this project, i should have it somewhere.
The idea is to apply a force to the backgeound to move it and check the position and add the backgeound again or move it to coordinate 0

Sorry xisco, but I didn’t get it

ok, lets try with a draw :sweat_smile:

Suppose screen size is 800600 pixels, you have a bk1 object which is an image with size 800600 to fill screen.Then you put another object like bk1 which starts at position 801,0.
you apply a permanent force to bk1 sprites to move left, when bk1.X()<-800 (completely out of screen) do bk1.X=801, so when one bk1 is out of screen you move it .
Will look for the GD code

1 Like

i think what xisco is trying to show is this:

Create an Object Variable for your Background (I am assuming your Background is a Sprite) at the Objects Panel. name it “Scroll_Speed”.

Condition: Scene —> At The Beginning of Game
Action: Common actions of all objects —> Variables —> Modify a Variable of an Object
set the value of “Scroll_Speed” to whatever you want. the lower the number, the slower it will scroll.

Condition: Common actions of all objects —> Position —> Compare X Position of an Object
X Postion of “Background” is <= -Background.Width()

Add an empty Condition.
Action: Common actions of all objects —> Change X Position of an Object
Object: “Background” - Background.Variable(Scroll_Speed)

The downside of using this method is that you will need to twiddle with the width of your “Background” to get it right, or there might be a visible gap where the two edges meet.

json file:

1 Like

Thanks guys, but still I was not able to solve the problem, I do believe you did your best in explaining the solution(really appreciate a lot) but as I am a non-developer its difficult form me to understand it, sorry for the same.
Here is what I have done, please take a look at my dummy project.

Link of my project

If you want to move the background in to a given direction at a given speed and you want it to repeat, an example is included with GDevelop called “Infinite scrolling background” it works exactly as xisco explained. It is very simple, all you need to do is is constantly swap two images to create the scrolling effect.

1 Like

hello swap…
just look this video :frowning: Easy way )

1 Like

Change the all “Background.Width()” to “Background.Height()”. As you are trying to do Y Axis scrolling, so the Height should be the focus.

From the looks of the JPG, your camera might also interfere with the scroll. What you want to try is place the camera + invisible force + turret on the same but different layer. Then have Background scroll object on the base layer.

made some changes to your json file:

you also place the scroll action on the wrong event btw.

Thanks guys, the background is looping now but how do I loop it upwards, means I want the background to loop in upward direction i,e ↑

Move the background on the Y axis instead of X and also make sure you are working with the Y position instead of X and replace object.X() with object.Y() and object.Width() with object.Height()

Hi I tried implementing it @audze had helped me regarding it, but the background is looping in bottom-top direction whereas I want it to loop it in top-down direction, as my game moves in top direction.
Here is what I have done.

My project files

First of all, move the background downward on the Y position.
Do + Background.Variable(Scroll_Speed) to the Y position of Background

And then swap the images the opposite way:
The Y position of Background is >= Background.Height() THEN Do = -Background.Height() to the Y position of Background