tile objects in 2D RPG

Started by
5 comments, last by Evan Gordon 8 years, 11 months ago

So im not quite sure how to word this question (seems like thats happening more and more in my programming these days)

anyways im making a RPG, simple top down old school legend of zelda like. i have a 2D array of tiles that are stored inside a map object and thats more or less gonna be the world of my game.

my problem may be just utilizing OOP styles with this, but im not sure. My question is, say i have N number of different tile objects. N could be huge in the long run, or maybe only reach about 100. im looking for a way to serialize? or give an easy to obtain reference to each different tile type so i dont end up spending hours searching for the right image and properties for a specific tile space in my game.

-.- i feel like i may have just rambles a lot of nonsense. if this makes sense to everyone out there id appreciate any help. if id doesnt make sense ill gladly try and clear up any misunderstandings.

Advertisement

Considering you're making a tile based game, you should have an editor for creating your world. So, the editor needs to be able to load the tiles, and give them unique ID's. The ID's could just be numbers, with 1 being the 1st tile it loads, but the ID's need to match the tile persistently (ie, it can't change), so it should be saved in a file somewhere (hopefully with a know format, like JSON). Then, when your editor creates your world, it just uses the Tile ID for the tile reference. When your game loads the map, it will look at the tile ID, then look into the tile Id file, and it will know which tile image to load based on the Tile ID.

Alternately, you could use a well know Tile map editor instead of re-inventing the wheel, like Tiled (and use a SFML Tiled map loader too).

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Thanks for the offer of the premade map loaders, but this project is a lot more of learning to make a game, and experimenting than it is trying to make something ill release.

what im more looking for is a method of numbering the tiles? say i just got by location in the .jpg file right to left, top to bottom

12345

678910

that works all fine and dandy for some things, but its not helpful at all for finding peices that look alike, or have the same behavior, i end up wit the way im finding and using the different tiles being arbitrary from their actual uses. does that make sense? but maybe i should just do that and am putting in too much thought to something that should be simple.

The truth is BeerNutts answer to your first post is still the answer to your second post.

When dealing with a bulk of assets for a game, various game editors are the correct solution to the question of how to manage them. This is one aspect of transitioning from small and simple games to more expansive games that is simply unavoidable.

If you're dealing with dozens of assets, managing them manually is a minor inconvenience at most.

If you're dealing with hundreds of assets, managing them manually becomes a significant inconvenience and a significant time sink.

If you're dealing with thousands of assets, managing them manually isn't even a viable option. Shouldn't even be considered.

In the end, working with editors is a major part of learning to make a game.

You shouldn't be "searching" at all.

A basic map implementation will have ...

1) a 2d array, mapping locations to tile types. (This will be loaded from your map file, which will be created by a map editor)

2) an associative array (aka dictionary, hashmap) mapping tile types to you per-tile data.

3) a 2d array, mapping locations to mobile objects in those locations (for fast collision detection and ai)

As it becomes more complex, you might split your map array into "chunks" or "patches", so you only need to load the part which the player is near.

I am mentoring someone working on a similar 2d rpg inspired by pokemon, in C#. If you would like to collaborate with him and be mentored, hit me up (davidj at gmail).

In general, you would just store an index, UID, handle, pointer or other 'name' in each tilemap cell, which refers to data that describes that tile. That's the easy part -- you have one unique thing (the tile) that reappears in many places, so you tag each place with a way to find the thing, then look it up; this pattern appears all over the place, not just in maps, not just in games.

A more interesting question is how you want to store the map cells. The easiest way is using a 2D or 3D array, dynamically allocated so that you can load maps of different sizes. This can be a bit wasteful of memory (e.g. if you have 'overhead' map layers with lots of empty space, you'll store a lot of 'empty' tiles in those cells, but this is not a problem on modern systems, though it can be a large annoyance if you have just one or few very tall layers (you spend an entire layer to represent just a few overhead tiles, multiplied by the number of layers needed). You can have a 2D array where each cell is a linked-list, which saves that unused memory, but can be more costly to iterate over. Or you can store in smaller chunks (say 8x8 tiles) and stream in only the chunks you need. Lots of options with different properties and tradeoffs.

throw table_exception("(? ???)? ? ???");

i think i might get it now. thanks everyone for your insight.

This topic is closed to new replies.

Advertisement