Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question is simple, but for me is hard to do! How to implement side (horizontal and vertical) scrolling for (i.e.) a 2d car game ? Both car and background must move. How to ? Thank you!

share|improve this question
3  
-1, not specific enough. What platform/language/engine/framework/whatever are you using? You say scrolling in all directions, do you mean the game is top-down? Why is both the car and the background moving? Do you have some images you can share to show the effect you want? Depending on your needs the math is going to be very different. –  Tetrad Nov 2 '10 at 20:08
    
Wow... ok, simply a top down game, with scrolling on all directions –  stighy Nov 2 '10 at 20:31
3  
if(up key is down) move everything down. –  The Communist Duck Nov 2 '10 at 20:43
1  
Your not going to get to much support when you pose questions like that. First, they indicate lazyness. I typed "Create a side scrolling game" in google and got a ton of hits, which tells me you have not done that. No one here on any of the Stack Exchanges is going to give a bit of information without seeing that you have put forth an effort yourself. You should first begin to solve the problem, research it, work on it more. Then asks specifics like "I cannot seem to buffer off screen images correctly" or "Or my camera's wont follow correctly". Good luck. –  Bryan Harrington Nov 2 '10 at 20:47
    
Ok guys, i'm sorry for the "bad" style of my question. In particular i'm asking a good "start point" to understand how to move "the background" and not my sprite... –  stighy Nov 2 '10 at 23:13
add comment

2 Answers

up vote 2 down vote accepted

Actually, your post indicates a very high level of laziness, but considering my novice days, I guess I might answer this.

In a top-down racing game (that is what you call a game that move on all fours, because the view is from the top of the car), basically the car is made to move over the tracks by "faking" track movement. For example: Consider the car is lying on the center of the screen. I push the move up key. We know the car has to move up the track. But what we do in actuality is we dont move the car ,but we move the track downwards. ie. for every movement of the car, the track is moved by the distance to be moved in reverse direction. So when you look at the game from the aerial point of view(top-down) you "believe" the car is moving. This is just the essence of a top-down side-scroller game.

And once you have accomplished this, you might want to add a "feel" to the acceleration. This can be done by adding a "braking factor" to the car at every instant in the gameloop also ensuring that the speed doesn't go negative.

Hoping you'd achieve what you want. Best wishes

share|improve this answer
add comment

I don't like moving the background, what I did for my 2d physics engine was:

  • Make a world class.
  • Make a car class.
  • Position the car relative to the world.
  • Make a camera class.
  • Position the camera relative to the world.

When you want to move the car, just change it's position relative to the world.

Note:

With the camera object you can implement zoom and scrolling easily.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.