Welcome to Phrogram Sign in | Join | Help
in Search


Side scroller speed change

Last post 07-07-2008, 9:33 PM by knubile. 2 replies.
Sort Posts: Previous Next
  •  07-07-2008, 8:33 AM 6837

    Side scroller speed change

    Hi all,

     I'm trying to help my nephew build a top down scroller racing game. Basically like the DriveMyCar program, but the road is much simpler. It simple goes straight. We will be including obstacles and power ups etc.. for the game play.

    I'm trying to build it myself first to get a clear understanding of the features in kpl, which is pretty amazing by the way. I'm a professional .NET developer, so I definitely know my way around code. 

    I couldn't really follow exactly how the DriveMyCar program handles this situation, so I was hoping I could get some help from here. 

     I put a bunch of road sprites on the screen that stack to fill the full vertical space. With every pass through the main game loop, we move it down by a certain Y value(called 'speed'). When a sprite is completely off the bottom of the screen, its moved to the top. This way we can get the full effect using about 15 sprites. Its pretty much like a treadmill. The end result is it looks like the road is moving down the screen. With a car placed at the base of the screen that can be moved left and right, we've got a pretty good first step. 

    Here's where the problem is. We want to be able to vary speed.  The issue is, when speed is increased, the amount the road sprites are moved is more than the last pass through the loop, so we end up with a little gap of a few pixels in the road. I'm pretty sure this has to do with the "treadmill" strategy, but I can't really figure it out. 

    What is the general strategy for scrolling games to handle changes in speed? Am I just doing something silly?

     If needed, I can post the code. 

     

    Thanks

     

  •  07-07-2008, 8:44 AM 6839 in reply to 6837

    Re: Side scroller speed change

    My guess without the code is that there is a bug in the way you reintroduce the new sprites to the top of the screen. I guess that you always reintroduce them at 0. This works great when everything has only scrolled down by one pixel.

    The treamill strategy should work fine but you need to imagine that the screen is actually bigger that the person playing the game will see. In a way you already do this becuase you draw the sprites off the bottom of the screen partly. If you imagine that there is an equally sized buffer off the top of the screen and realise that you can draw the sprites at negative Y positions then it should help you solve this.

    Hope that gives you enough of a hint to solve this yourself. If not then ask again and post the code. (use the options tab and attach it)


    Managed DirectX and XNA ? Check out http://www.thezbuffer.com
  •  07-07-2008, 9:33 PM 6864 in reply to 6839

    Re: Side scroller speed change

    That was it. I was putting the sprite back just off the edge of the top of the screen already, but the problem was it was placed after the sprites where moved down. This left the small gap between the top sprite and the one I just placed.

    All I had to do was offset it by the amount of pixels I was moving them by. 

     Thanks for the help. 

View as RSS news feed in XML