I followed the infinite runner tutorial to create an infinite platform. There are two grass platforms. They both move to the left at a speed of -100px/s. When the leftmost one goes out of view, it moves to the right, completing the loop.
Everything works fine as long as you don’t change the screen size! As soon as you change the screen size, there’s a gap between the two platforms… Can someone explain what’s going on?
UPDATE: I understand what’s going—the new platform position is the ScreenWidth—what I want instead is to put it immediately to the right of the other grass platform. How would I do that? They are both instances of the same objet.
On your scene editor, for both platforms, add a variable id, and for each give different number, 1 and 2.
after you can filter platforms with condition “object variable” in your eventsheet
Right… but how do i access the value of the instance variable in the action? I need to set the X position of one platform to the right of the other platform
All objects filter by conditions are same objects in actions.
So if you grass have the variable ID to 1, in your actions Grass is the grass with ID to 1.
As per the link I referenced above, there seems to be no way to directly reference arbitrary instance variables, and so the recommended workaround is to use scene variables to store the positions of each platform.
This approach works: store each platform position every render in separate scene variables. If the 1st platform moved out of screen, move to the right of the 2nd one (using the scene variables), an vice versa.