Tile Engine Considerations

BlitzMax Forums/BlitzMax Programming/Tile Engine Considerations

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

First of all why are you using pixmaps? They're much slower than Textures (TImage). Also you don't have to cut them up yourself.

LoadAnimImage("tiles.png",32,32,0,64) will cut a 512x512 file into 64 32x32 pieces.
DrawImage(tileImage,x,y,5) will draw the 6th tile (0 is 1st) at x,y


Anyway, my system is lower level than a tile engine. Think of it only as a software z buffer. I designed it to allow objects to change their depth easily without having to sort a big list of objects every loop.

It works by creating a ZBuffer object (there are a few kinds of buffers) and filling it with objects that extend the ZObject type. There are basic objects for all the shapes and images(ZRect,ZImage,etc.) that you can use or you can create a more complex object yourself.

The ZObjects can be handled in one of three ways. Staticly, Dynamicly, or Streamed.
Static objects aren't sorted before being drawn. They're sorted only when a buffer is in an 'unlocked' state and upon the locking of the buffer. Terrain / tiles make good static objects.
Dynamic objects are sorted before every draw. These are the whole point of the system. By keeping them separate they can be sorted that much faster.
Both dynamic and static objects remain in the buffer until freed. Static images won't be removed until the buffer is unlocked, although they won't be drawn either.
Streamed objects are removed from the buffer once they're drawn.
I can't think of a reason to use all three types at once, but you can.

Buffers extend ZObject so you can further segregate your objects. For example all GUI or HUD objects would always be above all game content so you can create a buffer for your GUI with a very large Z, make it static and place it in the main buffer. Then your GUI objects would only be sorted relative to each other.

That's it in a nutshell. Hopefully I explained it well enough. In practice it's easier to use than it is to explain or understand. The easiest way to use it is with all streamed objects and use only the main buffer.

Example:
'initialize max2d

ZDraw.Initialize(_STREAMED_)
ZDraw.SetBuffer(ZDraw.BackBuffer())

'from here just replace draw commands
ZDraw.Rect(100,100,30,30,z)
ZDraw.Oval(200,100,20,20,z)
'Text, image, plot, line etc...

ZDraw.Flip()

I can get close to 1000 images at 60fps in this manner. By managing the buffers myself using only static and dynamic objects I can get between 4000 and 5000 depending on how many of each type there are.

Hopefully that made more sense. I do plan on releasing this module once I optimize, tweak and document it.