0

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!

D34thSt4lker
  • 143
  • 2
  • 6
  • 1
    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
  • 1
    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. – House Sep 16 '12 at 15:35
  • I'm not asking how to create an entire game... Just the simple logic behind the side scrolling part of it – D34thSt4lker Sep 16 '12 at 15:41
  • Check out unity. Its a very developer friendly engine that is free to use and experiment with and it has some side scroller samples. www.unity3d.com – Alturis Sep 16 '12 at 14:56
  • 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

1 Answers1

0

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
else
    camera.x = player.x - screen_width / 2
end

draw_stuff(x - camera.x, y)
tesselode
  • 767
  • 6
  • 12
  • 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