Sign in to follow this  
Lord_Jabbercat

How does one go about making a tile engine?

Recommended Posts

Well, I don't know how to, but here goes: If all of your tiles are 32x32 and you wanted to move a sprite up the y axis, would you simply move the sprite up 32 pixels? I know about the map and all that kind of thing, Im just not too sure about the actual engine behind it!

Share this post


Link to post
Share on other sites
Quote:
would you simply move the sprite up 32 pixels?
yeah, pretty much. There are other ways, but that one works.

I made a load of tile-based games when I first started out. I generally used the same basic design each time.

Have a 2D array of integers. A 100x100 map (for example) has a 100x100 array.

You then have a "tile texture" - that is a palette of tiles. I liked to keep them as 1 big column or row (this can be limiting if you're wanting a huge number of tiles).

The integer for any given element in the original array corresponds to an element in the "tile texture".

So, with these two pieces of data, you can create a simple loop (for x, for y) that, on each frame, draws the entire map...

When the player wants to move, you can have a function like "Move( int iXDelta, int iYDelta)" such that Move(-1,0) would move the character to the left.

In this function you can have a big select-case construct that determines if the player can move in the requested direction. e.g "If (current_x + iDeltaX) is a wall, the player cant move. else, current_x-1".

-------------------

I stress that what I described above is very simple (but works) - there are many many ways that can be improved for graphical efficiency as well as general logical/data-driven efficiency...

The engine as such, unless you want a really high-level generic tile-based engine with scripting and pure-data-driven architecture, will be very simple... There's probably no reason to over-complicate it and compare it with a "normal 3D engine".

hth
Jack

Share this post


Link to post
Share on other sites
... Many thanks to Adobe Acrobat for locking up my X session and trashing the reply I just had written out. Spank you very much, closed source software. *drops the bird*

Now as I was saying, you could use an array, but a hashtable would be better (in my opinion). A hashtable is a construct that lets you store data into a lookup table as a key/value pair, like a database. in Java, the implementation is pretty straightforward. You just create a new Hashtable object and use get() and put() operations on it to store/retrieve your data by key. In C++, the implementation is more difficult as I understand it; though there is a std::map in the STL, you have more work to do in order to get it working. There's an example in "Thinking in C++, Volume 2", but neither acrobat nor ghostview seem all that hip to the idea of letting me copy/paste it right now. *sigh* Maybe a more experienced C++ guy can give you an example off the top of his head. (edit: check Addison Wesley's C++ STL book, here:)

http://www.aklabs.net/ebooks/Addison-Wesley%20C++%20Standard%20Library%20-%20A%20Tutorial%20and%20Reference.pdf

This'd be better than an array because, for one thing, you'd never have to worry about getting an array out of bounds exception from the map creator/map maker person putting the wrong array index into a map. You could just use whatever was in the file, check if it's in the hashtable, and draw the result. It also keeps you from having to go in and change the size of your array maximum size every time a new tile is added; it's dynamic, so it don't matter how many tiles you have. The performance and memory overhead are nill, especially if simple numeric keys are used. (I prefer string keys in most maps/tables, because it's more human friendly if you have to edit a mapfile by hand, but numbers are more efficient on the memory.)

As for everything else, yeah what the dude above me said.

[Edited by - andrewk3652 on December 3, 2004 1:23:01 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this