How to make side scroller game endless?

Can anyone tell me how to make an endless side scroller game endless? Please post me the sample code. Thanks

I've taught some a lengthy set of video tutorials on Endless levels and its definitely something that takes a lot of thought and a lot of code. I don't think you'll get much of an idea of how to do this with pasted in code here.

The 'endless' I meant is the side scroller game character just run and run and run and never stop until game over. Do you meant the same? Thanks

Yup, exactly

yeah i have built something like this too and made it work with physics too, quite proud of that, but the game is on pause for a while.


anyway - basically you need two 'platforms' and you move them from one side to other - as soon as one is off screen you put it back where it started.. repeat endlessly..


the code is indeed quite lengthy and not something that can be posted here.

OK. I think I can try. Please give me your link to the tutorial.

Can I just do like this?

if(character.position.x >= 100){//100 is the end position of the game
character.position = CGPointMake(1, character.position.y);//1 is the start position
}

The tutorial is here... cartoonsmart.com/endless-worlds-video-tutorials-for-swift-and-sprite-kit/ It's Swift though.


The problem with your example code is with an Endless style game, the character is usually staying in place and the world is what's moving. What your code is doing is assuming the character moves past a certain point and then it moves back. Which is going to be an abrupt jump.


Most likely you'll want to randomly generate platforms, or other objects to appear and then using the update statement move all of those to the left while the character stays in place ( it can jump up of course, but the x position is pretty constant). So when the level elements are out of the visible area, they are removed.


I wouldn't worry about re-using the same elements and repositioning them forward again. Thats going to be a pretty boring game after a while. The fun of an endless runner is "endless" possibilties. Which is why you randomize sections of the level to appear outside of the visible area and then move them into play.

My example code doesn't work. The character still running out of the background. Why?

How to make side scroller game endless?
 
 
Q