2D tile mapping

I’ve been trying to think of how the logic goes into making a 2D tile mapping system. I know that to save tile positions ( preferrably in layers ), you would save it in a similar style as this:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

1’s being say a wall sprite and 0’s being a floor sprite. You could have multiple layers stacked into a file such as Base, Fringe, etc.

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

You then assign the values that are parsed from the file into a 2-dimentional array ( say map[2][3] = parsedDataLatest ) or multiple if you have layers. That part I understand. Where I’m confused is to how to make tiles in the form of a class with an object for each tile. Would I have to create an object for each tile I want in say the example I gave above? Wouldn’t that make it limited to the size of the levels I make due to limits on how many object I create? What if I do create a very large amount of objects and just give the illusion of level limitation on size? Would that leave lots of memory being allocated to tile objects that aren’t being used in the level?

To elaborate on what I mean, I haven’t grasped the concept of how tiles would work in-game. In Game Maker, I would create a tile sprite, followed by a tile object ( technically I feel that these are just classes until I actually click in the level and place/create an object of that class ). Then, I’d create and place as many of that tile as I need. The character the player uses would then react to that specific tile object ( class in my conceptual mind ) via collision effects and gravity by vertical velocity. I’ve used things such as Game Maker to quote game design logic that I’ve learned, so sorry if this sounds like a GM term.

I’ve implemented collision, vertical velocity, and even moving directly to contact with objects that stops the player from moving ( so that they don’t bounce off it slightly or even increase velocity when it’s not needed ). These concepts I’m also fully at terms with, but if someone wants to explain something along those lines I’m more than delighted to read the tips.

I use C++ using SDL 1.2.15 with my IDE being Visual Studio 2008 Professional if it helps, but really I don’t need code to be made to explain. I just want a simple vanilla explanation as to how 2D tile games create tiles in their game, whether it be by creating a tile class with multiple tile objects for the level, or whatever.

Sorry for any troubles with conveying what I mean, any clarification needed will be done :wink: .

EDIT: in case someone comes by that sees “Game Maker” and instantly think that I’m a ‘noob’ for using it, I’d like to inform you that there’s nothing wrong with using toolsets such as GM to develop games and learn valuable development lessons by using it. When I think in code, I think in C++. When I think in game development, I think in Game Maker ( for the most part ). Is that so wrong? Just today I used a picture of an octapus caught on fire to help me remember a rule ( rule #8 ) that involved fire and distress. Since an octapus has 8 limbs, it helped me remember it. Abstraction can look unprofessional at times, but in the end who is the one learning and doing what’s needed and who is still trying to learn rule #8 in a booklet by memory?

For those who obviously know better than to rant on those who use tools such as Game Maker, or uses a different programming language than you, this isn’t targeted towards you 8) . I just got finished seeing someone mock a Ruby programmer because they thought “Ruby is for noobs, C is the way to go.”, so you probably know how I feel.

This is what I used for my game

http://www.parallelrealities.co.uk/2011/10/intermediate-game-tutorial-1-displaying.html

It doesn’t have layer support, but that’s just a case of adding another dimension to your array.

Thanks for the link! The tutorial answered my question.

Good luck with Edgar by the way 8) .

I needed a map editor or way to make it easy to put the map together. I found an editor made by a guy. I think it’s open source. It
s called d2d map editor and u can get it and other stuff at www.dannylum.com and it was easy to parse the map output in a game like at the paralel reality site.