Jump to content
  • Advertisement
Sign in to follow this  

C++ 2D side-scroller question.

This topic is 2380 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there. This might sound like a very dumb question but I'm having quite a hard time figuring out how side scroller games 'work'? I've been assigned the task of creating a 2D game with something like a 'breakout' clone being the minimum to pass. I would really like to push myself on this one so I've decided to try a side-scroller. We have been told that we're not allowed to use any external libraries so SDL is out of the question which is making this task quite tedious for me. I'm quite confused as to how you would actually scroll through the map, my gut instinct tells me that instead of getting your character to move, you would move the whole map closer to you. I've read this a few times on multiple websites but I just feel that this can't be right as you could, for example, drop enemies down a hole in the map just by moving the map left and right? Unless everything moves with the map? It just seems like that would be quite unnecessary to do... If anyone could help me on this that would be great!

Share this post


Link to post
Share on other sites
Advertisement

Hi there. This might sound like a very dumb question but I'm having quite a hard time figuring out how side scroller games 'work'? I've been assigned the task of creating a 2D game with something like a 'breakout' clone being the minimum to pass. I would really like to push myself on this one so I've decided to try a side-scroller. We have been told that we're not allowed to use any external libraries so SDL is out of the question which is making this task quite tedious for me. I'm quite confused as to how you would actually scroll through the map, my gut instinct tells me that instead of getting your character to move, you would move the whole map closer to you. I've read this a few times on multiple websites but I just feel that this can't be right as you could, for example, drop enemies down a hole in the map just by moving the map left and right? Unless everything moves with the map? It just seems like that would be quite unnecessary to do... If anyone could help me on this that would be great!


I'm working on my first side-scroller too! I was actually confused about the very same things as you, so I posted a question. Maybe this thread can help you out:

http://www.gamedev.net/topic/614497-sdl-sidescroller-help/page__pid__4881232#entry4881232

Share this post


Link to post
Share on other sites
In my 2D sidescroling game I move the camera and the player. I think that's better than moving all the objects on the map, since moving all objects will get ineffective when there's a lot of objects in the level.

Share this post


Link to post
Share on other sites
Generally speaking, a tile-based 2D platformer renders the entire screen every frame by taking the position of the top-left of the screen in theoretically "world" coordinates and stepping across, rendering each tile that is visible in the appropriate place, then rendering actors like the player and other objects at their appropriate screen position based on their "world" position.

In effect, aside from when rendering you never think about screen positions. Map stays still, player moves in world co-ordinates, objects move in world co-ordinates, collisions are done in world co-ordinates. It is only during the rendering process that these co-ordinates are converted into screen co-ordinates based on the position of the camera.

Normally, you would update the camera each frame based on the player position.

Share this post


Link to post
Share on other sites

Hi there. This might sound like a very dumb question but I'm having quite a hard time figuring out how side scroller games 'work'? I've been assigned the task of creating a 2D game with something like a 'breakout' clone being the minimum to pass. I would really like to push myself on this one so I've decided to try a side-scroller. We have been told that we're not allowed to use any external libraries so SDL is out of the question which is making this task quite tedious for me. I'm quite confused as to how you would actually scroll through the map, my gut instinct tells me that instead of getting your character to move, you would move the whole map closer to you. I've read this a few times on multiple websites but I just feel that this can't be right as you could, for example, drop enemies down a hole in the map just by moving the map left and right? Unless everything moves with the map? It just seems like that would be quite unnecessary to do... If anyone could help me on this that would be great!


How are you going to be drawing images to screen if you can't use an external API? You going to write directly to graphics memory? I doubt that.

Is it limited to DirectX or something instead?

Just wondering.

Share this post


Link to post
Share on other sites


How are you going to be drawing images to screen if you can't use an external API? You going to write directly to graphics memory? I doubt that.

Is it limited to DirectX or something instead?

Just wondering.


Hi, yeah I am, bit blitting to the hDC. I gave up on the scroller idea, couldn't figure out how I'd do it without an external API for the camera. Thanks to everyone who helped though.

Share this post


Link to post
Share on other sites

[quote name='BeerNutts' timestamp='1321047836' post='4883054']
How are you going to be drawing images to screen if you can't use an external API? You going to write directly to graphics memory? I doubt that.

Is it limited to DirectX or something instead?

Just wondering.


Hi, yeah I am, bit blitting to the hDC. I gave up on the scroller idea, couldn't figure out how I'd do it without an external API for the camera. Thanks to everyone who helped though.
[/quote]

You don't need a camera.


Picture if you will a source image that is say 4096x4096 and your window is 640x480. All you are essentially doing in your "camera" is copying a 640x480 rectangle of that 4096x4096 greater image. That said, you generally don't use a single very large image for your background, but instead a number of tiles that compose a larger image.

So to use the about example, say your character is in the middle of the world, his coordinates would be x=2048,y=2048, so you would merely copy for your 4096^2 image, a 640x480 rectangle at that position to the screen. When you move, you update these coordinates within the source image.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!