Jump to content
  • Advertisement
Sign in to follow this  

Side-Scroller Tutorial

This topic is 4220 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

Does anyone know a good side-scroller tutorial in C++ and SDL? I know that's a little specific but hey, that's the point ;). If not, what about just one with an open-source code file. Thank you

Share this post

Link to post
Share on other sites
Well i do not know of any tutorials for such a thing but i do not imagin in it would be to difficult!

Just draw your ship on a scrolling Back Ground and have some enemys spawn in on one side of the screen!

You can use srand to give a random starting point to the enemys.

and when the score reachs a certain point double the speed of the enemy.

to do a scrolling back ground can be tricky but basicaly you make your self a back ground image the same size of the screen works!

and then draw it move it back and just draw from however far back forward of the image and the draw the remainder lets see if i can make my point more clear.

|-------------| < Background when first drawen

Move it so your only draw a few pixels less of the image witch you can do with any
Blit function


and then draw the remainder in any case finding a tutorial for a scrolling back ground should not be to hard!

as for Collsion Detection IE: a bull fired at an enemy
you can use Vector math or just use Rect Collison detection

Hope the helps out abit!

Share this post

Link to post
Share on other sites
I will assume that you are referring to a tile based side scrolling game such as Sonic or Mario.

I am currently working on a top down tile based game and my current implementation uses a “Level” class and a vector of vectors of tile objects to represent the 2d array.

For the map editor I decided to use Mappy and for scrolling I implemented smooth scrolling with help from the article here:

Smooth Scrolling a Tile map

The first step I did with this regard was to take your player position (pX and pY) and then from that calculate the display position (dispX and dispY). I know I wanted to bound the display so:


Where TileXCount and TileYCount are the number of tiles horizontally and vertically in the level, WinWidth and WinHeight are the dimensions of the display area and TileWidth and TileHeight are the width and height of a single tile.

Then the position on the map is equal to:


The Map x and y offsets are equal to:


Now the number of tiles that can be displayed across the width of the window and the height is equal to:


The number of tiles to actually draw is:

TileDrawYCount=min(WinTileYCount, TileYCount-MapY)

Then you run a for loop for the TileDrawXCount and TileDrawYCount and to get the position at the array you get:

And the position of the tile is equal to :



And to draw an object on the screen all you need to do is:

PlayerDrawX= pX-DispX
PlayerDrawY= pY-DispY

And to convert from screen coordinates to coordinates in the map you do the reverse:


of course the actual tile position would be:


At least these are the formulas that I used. Some of the formulas I developed on my own and there might be much easier ways to do them ;) .

Of course all of these variables are meaningless without a solid framework. It is a good idea to use an OOP based approach and to not hard code things.

For an example project you could check out Dave Gnukem: Dave Gnukem

I hope this helps you on your path and that it can also help other people.

Share this post

Link to post
Share on other sites
One of the better sites I've seen is Jump 'n' Run Dev. It's no substitute for knowing how to program: it covers the techniques but won't hold your hand.

Learn to program first, and then go from there.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!