Best Way to Do an Endless Side Scroller

I'm just trying to understand the best way to do this. Right now I'm trying to set it up with a scrolling background and an actor the stays on the left side of the screen. But, im having problems with the scrolling background. My scene size is 480 x 320. To start, Im using 2 instances of the background actor, one on screen, one directly off the right side. I have the background actors linear velocity X set to -150, so that it moves from right to left. When the background is completely off screen(self.positionX = -240), I use change attribute self.positionX to 720. The background does loop but I get gaps each time it loops. These gaps vary in width, sometimes no gap, sometimes very little, sometimes larger.

So, is that the best way to setup an endless sidescroller? I have reach the point of spawning actors yet but I plan to recycle them rather than constantly spawn new actors. Not sure how that will work yet.

Answers

  • ericzingelerericzingeler Member Posts: 334
    @JackSoft

    Check this out: http://ezinterweb.com/gamesalad/platform-spawner

    I'm currently making my third side scoller game for iOS. Take it from me, using the above method will save you from the agony of puling your hair out strand by strand.
  • JackSoftJackSoft Member Posts: 27
    @ericzingeler

    Thanks for the reply. I actually have that example already and its really interesting. So are you saying that the best method is to setup static actors throughout the scene? Static backgrounds as well?
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    Someone here recently (last week I think) did a 6 digit wide scene for their endless scroller and it went horribly wrong with speed/lag issues. I'm not saying don't do it just make sure you test speed issues first before you get too far into your game and close to shipping it over to Apple. You don't want to have to start again when you're that close.

    You can easily make smaller backgrounds scroll together and remain joined without gaps.
  • JackSoftJackSoft Member Posts: 27
    @kevincross Yeah I was wondering about lag in such a long scene. It seems to be working out for @ericzingeler if he is on his 3rd side scroller with the method. I'm now having luck using wrap x on the scene and leaving my hero stationary on the X axis.

    Now I'm working on recycling actors for pickups and enemies/obstacles. Actually, right now I'm stuck on how best to destroy/hide bullets/weapons without them wrapping around.

    My scene is 480px wide. My bullets are 10px wide. So my thought was to destroy/hide the bullet when it reaches X = 475px. That works. But when I go wild and loose 5 or 6 bullets, 1 or 2 break through that rule somehow and wrap around. Then eventually, at random, will destroy the next time or maybe the 2nd or 3rd time they wrap around. Weird. Any ideas?
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I didn't use wrap when I was mucking about with a vertical scroller so I've not worked with it yet. In my version I destroyed them when they went so far off the screen like you are.

    Change your x = 475 to x >= 475. This should catch any that misfire at 475.

    If that still doesn't work add a timer to the bullet to automatically destroy after x amount of time
  • JackSoftJackSoft Member Posts: 27
    @kevincross Yeah im already using >= 475 and its not catching them. Also, I tried an invisible 1px wall right inside the right edge to destroy the bullet on collision but they were still breaking through at random. Now i have a timer and it works but seems a little unreliable due to different frame rates. I guess it will work until i find a better option. Maybe make it fall off on the Y axis or something if it misses the enemy.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    Try a much bigger invisible wall. It needs to be bigger than the bullet plus as big as the distance your bullet travels every frame. If your bullet travels 10 pixels every frame, and your billet is 5 pixels wide then make the invisible wall at least 15px. It shouldn't miss it then.

    Base this on the biggest distance your bullet can possibly travel.

    Or don't worry about calculations and make the wall 100 or 200px wide.

    Put the wall outside of the scene though, unless of course wrap wraps the moment it goes off screen, in which case ignore everything I've said :)
  • UtopianGamesUtopianGames Member Posts: 5,692
    edited September 2013
    The best one i have done is Jet Pack Joyride, the hero resets to the beginning of the scene when he reaches the end with the scene being 10,560 long on iPhone this gave me enough room to make random coin drops and varied levels depending how many time you made it to the end.

    Heres a quick vid of it in action.



    Nightmare Run also resets the hero if you don't collect all the lanterns to wake up from the Nightmare.



    You could also keep the hero still and move the platforms like my other one.



    Or do it like Eric suggested so theres 3 options.

    Darren.

  • JackSoftJackSoft Member Posts: 27
    edited September 2013
    @kevincross Haha wrap does wrap the moment it goes off the screen. However, ive just set a rule that basically says, if enemy missed, slow way down on the x axis and accelerate down on the y axis. Basically, fall off and destroy. I think would look better than the bullet just dieing in mid air.

    @DeepBlueApps Your Jet Pack is great. I actually purchased the Tap Tap Runner template from you earlier and instantly learned a great deal about what I need to do. Thats where the scene wrapping idea came from. So I'm simply wrapping a 480px scene and plan to change backgrounds based on time. Actually, I'm getting ready to load Tap Tap back up and look into how you were spawning pickups and enemies(mushrooms i think it was.) Great templating btw! I just looked at Platform Engine V3 and that's very cool. Also downloaded bumps on my iphone today. Though i cant seem to locate your jetpack template now?
  • DoguzDoguz Member Posts: 500
    edited September 2013
    Hey @ericzingeler I just tried to grab your template to take a look and did you remove it from Dropbox already?

    EDIT. Got it.
  • UtopianGamesUtopianGames Member Posts: 5,692
    edited September 2013
    @JackSoft heres the link http://www.deepblueapps.com/jetpack-template/ you can also use the search box in the top right of the site.

    Thanks for buying Bumps i hope you enjoy it.

    Darren.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    @deepblueapps I think the problem with the long scenes is that people don't code efficiently and puts lots of bloated code on the scene. As you prove performance is about how well one codes not design specifics.
  • JackSoftJackSoft Member Posts: 27
    @FryingBaconStudios What are some things that devs might do to improve performance in a longer scene? What are the "pitfalls"? <-- now thats punny right there. But really, what should we avoid?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Watch my video on intergraded code. This will help you understand how to build highly efficent code. Just click the link in my signature.
  • JackSoftJackSoft Member Posts: 27
    @FryingBaconStudios Just watched. Excellent video. Would you say that tables are a big part of your logic normally? In that example, using a table seems to be the key in limiting the number of rules you use. Well, that and incrementing your route attribute. Very good logic.

    Do you have a process when designing your logic? I know you mention spending the extra time up front do develop your logic, but I'm wondering if you've developed any habits in laying out initial logic.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I learned logic being a control systems designer for nearly 30 years. It takes time to learn. The key is learning all you can about gamesalad. Watch lots of videos and take notes. Every video will teach you something about creating logic in GS. Don't be distracted by well this video is about doing a health bar et.. Building a health bar video isn't really about a health bar as it's a video on how to grow and shrink and actor based on an external attribute.
  • JackSoftJackSoft Member Posts: 27
    edited September 2013
    @FryingBaconStudios Excellent advice. I'm coming from a web dev background so my logic experience is in the form of PHP, Javascript and Ruby. In coding, I find that no matter the language, logic is logic. I know that GS is no different but I'm still in the early stages of learning everything. Thanks for your advice, its top notch!
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Then as you would know the more knowledge you possess about GS the more concepts you have to consider for your logic or how you can integrate multiple ideas. Taking the time to practice and learn GS pays off when you do build a game or app.
Sign In or Register to comment.