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.

Newcomers DBPro Corner / 2D Tile Help

Author
Message
LoneWolf155
13
Years of Service
User Offline
Joined: 28th Sep 2011
Location:
Posted: 28th Sep 2011 20:10
Hello

I am creating this post because I find myself needing help in understanding how 2D tiling works.

I know that this requires the use of arrays, but I have had a hard time finding a detailed explanation that relates to how I want to use it. What I really want is an explanation of the theory behind it so that I can get a good understanding of it.

An example piece of code as to how you would accomplish it using the Dark GDK in C++ would also be helpful but an understanding of the theory behind it is my main concern.

Note: The reason why I am asking is because I would like to create a 2D game which allows for the main character to move about in a larger environment. I have created several 2D games in the past but they either had a scrolling background or made use of a single, unmoving background.

Thanks in advance!
Webber
13
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 28th Sep 2011 23:01
Well the arrays are used for all of the data for the tiles, and most importantly the X, Y world positions of all the tiles.
The tile positions are usually offset based on the size of the tiles, kinda like a big grid positioning system.

Also all of the tiles should move in the opposite direction of the position of a virtual camera. For example if your character is moving to the left, instead of moving the character to the left you can make all of the tiles move to the right.

You can use a 2D array or a one dimensional array.
If you use a 2D array, each peace of data in the array should only need one number, the type of tile that needs to be drawn. But with a 2D array, you will be limited specific sized box shaped map, and if you don't use all of the data in the box, you could have large amounts of useless empty array data.

With a one dimensional array you can use strings for each of your tile's data, or you can use sets of numbers for all of your tile's data. You could have a lot more power in controlling the data in the array. For example a one dimensional array will have no empty values, and you won't be stuck in a box.

You could use a 2D array a little differently and make the first dimension the tile number, and the second dimension all of the data for the tile.

There are multiple ways of using arrays for storing your data. Just use the one that works the best for whatever your doing.

Personally, I think that a one dimensional array is the easiest to work with, and they can do everything that a multidimensional array can, and in some cases even more.

I like games, and stuff.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 30th Sep 2011 15:49 Edited at: 30th Sep 2011 15:50
I agree with most of what Webber said except I would go with a 2D array as a class. I'm still a beginner at c++ but I'd recommend something like this:


So, this would create a 100x100 grid (10,000 tiles) with each tile possessing it's own x, y values as well as sprite numbers. You should then be able to work out your systems (I hope you like for loops ). Then to scroll, you'd increase/decrease the x, y values according to the players input. e.g

A lot of this is theory but I hope it's a starting point. Good luck.

LoneWolf155
13
Years of Service
User Offline
Joined: 28th Sep 2011
Location:
Posted: 3rd Oct 2011 21:51
Thanks for the feedback guys. I should be able to make use of this to create what I need. I'll be back if I have any further questions

Login to post a reply

Server time is: 2024-11-22 12:07:15
Your offset time is: 2024-11-22 12:07:15