Problem with the 'Getting Started' tutorial ground moving [Solved]

Hi, I’m just starting out with Defold and I am stuck right at the start where we have the script for moving the ground. I looked at the video and the ground is moving continuously and the image is repeated. In my game, this isn’t happening and all the ground objects move to the back of the screen instead.
Here is an image of my ground collection:


And my code is
`local pieces = {“ground0”,“ground1”,“ground2”,“ground3”,“ground4”,“ground5”,“ground6”}

function init(self)
self.speed = 6
end

function update(self, dt)
for i, p in pairs(pieces) do
local pos = go.get_position(p)
if pos.x <= -228 then
pos.x = 1368 + (pos.x + 228)
end
pos.x = pos.x - self.speed
go.set_position(pos, p)
end
end

Here is an image to help see my problem better

Solution:
I ordered the sprites one after the other using the sprite’s X position instead I should’ve used the game object’s X position

You only placed 6 ground objects. On the tutorial he places 7!

Uhm, there are seven ground objects there? ground0, ground1, ground2, ground3, ground4, ground5, ground6

One is on top of another. On the preview you can only see 6 of them

Oh, Well I fixed that but the ground is still not moving smoothly, all of the ground gets moved to the showing blank space instead of being continuous like the video

Make sure the ground pieces are all of the correct size and laid out properly one after the other. Each one should be 228 pixels wide if I’m not mistaken.

I fixed it. Turns out I positioned the sprites with the X position and not the game object’s X position

2 Likes

Ah, yeah, that would trip things up for sure! Good that you figured it out!