Endless Scroller Using Corona SDK

Last time I showed you how to create a life-meter using a beating heart with Corona SDK.  This time I’m gonna show you how to do an endless scroller.

The source code can be found at https://github.com/funkyvisions/EndlessScroller

Here’s a video demonstration.

This is done using the following sprite sheet.


There are normal top and bottom wall segments as well as an intro and exit segment (we don’t use the exit, since this is endless).  Each hump is broken up into 3 segments that are 64 units wide.  See the walls.lua file for how this is done.  The code pre-generates 100 wall segments, which we will play over and over to simulate an endless cavern.  You can change NUM_WALLS if you want to make this longer.

Once we have all the walls generated we produce enough of them to span the width of the landscape screen (including a buffer on either side).  Then we start scrolling the walls with each display frame.  Once a wall reaches the left side, we remove it and add another wall to the right side, and continue this process indefinitely.  If we wrap the index, then we start over at position 2 (remember we skip the intro segment).

I added a ball with a distance joint just to show that the walls have underlying physics objects that can be collided with.  These are defined in the shape attribute of each segment in walls.lua.  Enable physics.setDrawMode( “hybrid” ) if you want to see what they look like.

You can speed up the scrolling speed by changing WALL_SPEED.  You could either do this dynamically as the game progresses or each level if your game is level based.  You can also change the difficulty of the cavern by changing DIFFICULTY.  This is how often a wall is generated during the pre-construction phase.  Don’t set this less than 3 as each wall has 3 segments and they would overlap if you went lower than that.

I hope this gives you an idea how easy it is to do a scrolling game using Corona SDK.


Leave a Reply