Page 1 of 1

2D tile game question

Posted: Thu Jan 23, 2014 9:04 am
by UUICEO
I'm totally new to the graphics end of programming and I have a question regarding layering of tiles and how it works exactly. I'm going to be having sprites going inside of buildings and under bridges but I'm not sure how to layer the tiles to be able to do that. I searched the forum for layering tiles but didn't come up with much. Any help would be greatly appreciated.

Re: 2D tile game question

Posted: Thu Jan 23, 2014 3:59 pm
by J. Baker
Read all of this topic. There is a layer example. ;)

http://forum.purebasic.com/english/view ... a1985763d3

Re: 2D tile game question

Posted: Thu Jan 23, 2014 11:53 pm
by citystate
basically it comes down to the order you display the sprites to the screen - later sprites would appear to be on top of earlier sprites.

so, for a three layer display:
1) display all your background sprites
2) display all the character/object/wall sprites
3) display all the "overhead" sprites

should do the trick

Re: 2D tile game question

Posted: Sat Jan 25, 2014 8:22 pm
by UUICEO
I thank you for the info. I'm not completely understanding how this works but I will figure it out.

Re: 2D tile game question

Posted: Thu Mar 20, 2014 5:04 am
by Zach
UUICEO wrote:I thank you for the info. I'm not completely understanding how this works but I will figure it out.
Think of it this way. When you build your Procedure that will draw/redraw your graphics to update the scene, all you have to do is draw them in the proper order, or Z-Level. Even though 2D sprite/tile games use simple X/Y coordinates, you still need to take Z coordinates into consideration, because the Z axis controls the depth at which an object is drawn. That is, how "deep" it is in the scene.

Think of it as like Disney's early animation technique of using a multi-plane camera. By positioning traditional animation cels at various positions, and controlling how and when they move, you can simulate a 3D / Parrallax effect which can give you depth of field and make a scene feel 3 dimensional.

So let's say you have a scene you want to build. You have a town square and in the center of it is a fountain. We have some shops and houses as well, some outdoor picnic tables, trees, the road is cobblestone and it cuts through large patches of green grass, with various flowers, bushes and shrubbery growing out of the ground..

The first thing you draw onto your screen buffer would be all the ground tiles. That would be grass, cobblestone for the street, perhaps some other mixed tiles showing different textures of grass, specs of dirt or flower patches, etc. If you had a stream running through the town, you might place those water related tiles as well.

The second thing you draw would be your "props" layer. Mostly this will consist of things like your Trees, Houses, Shops, fences, shrubs and bushes, picnic tables, and things like that.

The third thing you draw would be your characters, and perhaps some other props that need to be drawn on top of everything else. Like say a horse and buggy traveling through the town.

Part of what you draw and what layer it is in will also depend on any special effects you might want to do, relating to things like which tiles are passable or not passable, or if for example you want to make your character pass "behind" a tree as he runs through the area, or you want to make sure he is not covered by the tree sprite when he runs in front of it.

2D Tile based games may appear simple, but they can be very complex and can deal with a lot of different problems in their own unique way; this was just a very simplified overview of what you want to consider when setting up your drawing order for sprites