2

I want to create an infinite game background like 'Binary Rush' or 'Stay in the line'. The background could be a simple track. It's sort of like a random racing road track.

Currently I have used a single SKShapeNode to draw the path, and just set the lineWidth to a big number. I use var path = CGPathCreateMutable(); to create the random track. Apparently this is not the ideal solution since the track is restricted to a single line. I would like the track could be expanded with different width or even add some obstacles inside the track.

So my questions are: 1. For those two game, are their backgrounds just images, and when scrolling, it just load a random one? 2. How could I random generate those tracks, with the flexibility to change its width or add obstacles inside them? 3. How to combine the different segments of those tracks, I assume not to create an infinite long path. Should split it into different segments and removeFromParent once the segment is scrolling off screen.

Thanks a looooooooooooooot!!! :)

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
artekr
  • 23
  • 3

2 Answers2

0

I would like to have a say based on my experience though i have less experience in developing games

I had a requirement in a game where i need to have an infinite bar rolling on the screen on which the a hero runs i have created that infinite running bar using an image.I have used an image more than size of the screen and whenever it reaches the end point of the image i used to reset that image to original position there by creating an infinite bar with some specific velocity.Hope this helps though it doesn't answer all your questions.

yashwanth77
  • 1,820
  • 1
  • 12
  • 17
  • Thanks for your answer, so you mean the path is pre-defined and convert to a texture or image? – artekr Dec 11 '14 at 16:23
  • Path is predefined in the sense i have only one path which does not change dynamically as you needed but we can do that using images ang placing them using random function – yashwanth77 Dec 12 '14 at 05:44
0

Use the method you are using with ShapeNode. Instead of making the line width big, make another line that is essentially a copy of first line that is shifted over a particular amount of pixels. That will give you boundaries (like a road). You can set collision and contact events to prevent the car from leaving the road or for damaging a car that hits a wall, etc.

How many pixels you shift the second wall over will let you control the width. You can easily make the track get wider or slimmer depending on the shift.

Create an algorithm that randomly places objects in the track. You could use the two lines that are boundaries to calculate where you should spawn these objects.

meisenman
  • 1,818
  • 1
  • 15
  • 25