Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to create games with scrolling?

I'm still pretty new to game programming and any tutorial that I have worked with stuck to only games with the initial screen. I want to start creating my own games but there are a few things that I still need to learn. One of them is how to create a game that side-scrolls. For example; Mario... Or ANY type of game like that...

Can anyone give me a small example to create something like that. I'm not asking for any specific language because currently in school I am learning javascript but I know some c++/java/processing/objective-c as well. So any of those languages would be fine and I could probably implement it in any of the others...

I have been searching for some help with this for a while now but could never actually get any help on it.

Thanks in advance!

share|improve this question

marked as duplicate by Byte56, Tetrad Sep 16 '12 at 16:37

This question was marked as an exact duplicate of an existing question.

Check out unity. Its a very developer friendly engine that is free to use and experiment with and it has some side scroller samples. – Alturis Sep 16 '12 at 14:56
Do you need help with the scrolling or the platforming or what? This isn't very specific. – tesselode Sep 16 '12 at 14:56
i believe the scrolling. kind of how to actually implement the idea of scrolling, like you run right and the screen moves too – D34thSt4lker Sep 16 '12 at 14:59
thanks, i got unity a while ago and never used it. Is it only 3d or both? My professor says we will be doing it before the end of this semester but seeing how she teaches and how the class reacts, we might not... But I will definitely look into it sooner or later. thanks! – D34thSt4lker Sep 16 '12 at 15:00
How to create an entire game is a bit too broad. You may want to start this and ask questions about the specific problems you come across. – Byte56 Sep 16 '12 at 15:35
up vote 0 down vote accepted

To accomplish scrolling, have a camera x and y (or in your case, maybe just x) variable that you change based on the position of the player. Then draw everything (except for the player) at their normal x and y position minus the camera x and y positions.

For example:

if player.x < screen_width / 2 then
    camera.x = 0
elseif player.x > level_width - screen_width / 2 then
    camera.x = level_width - screen_width
    camera.x = player.x - screen_width / 2

draw_stuff(x - camera.x, y)
share|improve this answer
Thank you very much for this! I will give this a shot. Just quick question on the camera class... Is it just going to be an x value? or are there going to be other things involved too? (well besides the y if movement goes across the y-axis as well)) – D34thSt4lker Sep 16 '12 at 16:08
I don't think you would need anything else. X and Y should be it. I've never needed anything else. – tesselode Sep 16 '12 at 19:59
Thanks very much! already started working with this setup. – D34thSt4lker Sep 16 '12 at 20:48

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