Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / 2D Tile - How do I setup and scroll a background?

Author
Message
GTmauf
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 12th Feb 2008 03:55
Hi all,

I'm very new to game programming and have been reading alot lately. I'm planning on making a side-scrolling game and have read that for collision detection and other reasons that using the scrolling tile setup is best. On the other hand I can't really find anything that is clear on how to do this in C++/DarkGDK. I have read lots of different documents about tile system and scrolling but can't come up with a clear idea on how to do it with C++/DarkGDK.

I have messed around setting up a background using a two-dimensional array with 1's and 0's and then placing an image on all the 1's but I don't quit understand how I would scroll that or detect collision with the DarkGDK.

I'm also not sure what type of file I should load as the "tileset." I have seen where some loaded multiple files and where some loaded one file that had numerous "tiles" on it. I know this is very long and vague but I'm in need of a starting point on where to go from here.

Any tips/advice/sample code would be great. Thanks for any help.
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 12th Feb 2008 16:29
Sounds like you have made a start.
Instead of using just 0s and 1s in your array, why dont you use the number of the tile you want to use. Im assuming that your tiles are all the same size - for example 32x32...

For two layers you could simply use something like this to draw it:



and to make it move:



There are of course a few optimisations that can be made to this code...
GTmauf
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 13th Feb 2008 02:05
Thanks for your reply Scottie Dog.

For the most part I understand what you are doing, but there are just a couple things that are still a little fuzzy.

I'm not exactly sure what your "BackMapPos" and "GX_TILE_START" are. Also I'm not sure where I would use the two-dimensional array in what you have written.

I see that you are using BackMap[] and FrontMap[] but those are both normal arrays.

I'm sure what you have written is much more optimized than what I have. I just want to make sure I fully understand it.
GTmauf
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 13th Feb 2008 14:20 Edited at: 13th Feb 2008 15:24
To give you an idea of where I am at, this is what I have so far.

MikeyK65
17
Years of Service
User Offline
Joined: 14th Dec 2006
Location: Cheltenham, UK
Posted: 15th Feb 2008 13:22
Hi there GTmauf

Without seeing Scotty Dog's full code I am guessing that BackMapPos and FrontMapPos are variables that hold the "position" of the scroll, e.g. if you have scrolled the screen to the right once then they will be equal to 1. if you scroll again, they will be 2, etc.

GX_TILE_START sounds like it is an offset to get the image number, e.g. if you were storing all your images sequentially, e.g.

SHIPIMAGE = 1
ALIENIMAGE1 = 2
ALIENIMAGE2 = 3
ALIENIMAGE3 = 4

Then you would create another variable to point to the 1st number of a sequence, e.g. in the above example I could have ALIEN_IMAGE_START = 2
Then for every image I could do
Image1 = ALIEN_IMAGE_START
Image2 = ALIEN_IMAGE_START + 1
etc.

Finally, the idea of using a 1D array is to make the program run quicker. You just need some maths to get the right element for your use.
If you have your example above, you have 13 cols and 10 rows. You have created this as a 2D array. However you could just use a 1D array of (13 x 10) elements, e.g.
int level[ROWS * COLS];

Then to access elements you would use an offset, e.g.

top left element you use level[0]
top right element you use level[12]
2nd line left - level[13]
bottom right = level[129]

Hope that makes some sense and helps?
Mike
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 16th Feb 2008 12:12
You hit it on the head MikeyK65.

GX_TILE_START is the image number of my 1st tile.

FrontMapPos and BackMapPos are both positions in the arrays which I need as my tiles are scrolling all the type. Just a quick note I start at the end of the array (well a screen in from the end anyway) and work to the start (as Im scrolling the tiles down then screen - it just seemed the easier way to do it).
GTmauf
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 18th Feb 2008 23:31
Sorry, I haven't replied til just now. Thanks alot for your help guys. I currently have my background scrolling. I just need to work on the collision detection which I think I have a good feel for. I'm just going to put my tiles into a struct and make an array of that and it will hold my imageID and whether or not it's passable(able to be walked through) and as I move my character I will just check to see if the tile he is trying to go through is passable or not.

I think this will be a good easy way of doing it. If you know of a faster/better way, I'm glad to take any input. Also, i'm a little confused on how to make jumping work smoothly, I would like him to be able to jump around just as you would in Super Mario Bros. I know you have to deal with their current velocity, etc. I'm just not sure on how it fits together.

Thanks again!!!

Login to post a reply

Server time is: 2024-09-29 11:18:19
Your offset time is: 2024-09-29 11:18:19