Z-Order for 2D Isometric game

Started by
3 comments, last by RDK1LL 17 years, 9 months ago
Hi! I'm currently working on my third game, which is a 2D Isometric game, and have come to a complete halt while trying to implement a Z-Order to my game objects. All collision dection works sweet, and I can move my player behind all objects in the game. But I want to have NPC's in the game, (enemies and such), that can walk behing objects and each other. Im assuming that I would draw everything from right to left top to bottom, according to their z-orders,(eg. enemy1's.xpos < enemy2's.xpos, therefore enemy1.z=1, enemy2.z=2;) is this right? If so how would I go about assigning each bobs z-order?
"For every answer, I have a question."
Advertisement
Assuming that lesser x positions are closer to the screen, then yes, your current method should work. To solve your other problem, I would say that you should include the "bobs" in your sorting of everything else. I may be misunderstanding your problem, however. Why are the "bobs" a problem for you? Have you already tried the method you used on the other objects?

Why do you need to manually sort through depths? If you're not planning on using alpha-blending and you're using OpenGL (or DirectX I assume), you can let the API handle the sorting for you and enable an alpha test.
Whoops, I meant left to right and top to bottom.
Thanks for that Rendaw. Sorry bout that Im asking the question wrong.

The method Im using is only temporary and I wanna update it. Right now they are only drawn in a fixed order, and the main player pos is tested between each one, which is pretty darn slow heh heh. So nothing is REALLY sorted properley.

The game is set in a hotel with about 30 odd rooms.
The objects are all different sizes(ie, tables, chairs, bookshelf...) and wont be moving. Im just trying to figure out how to draw them in now, with other objects(people) that will be moving.

This is the only thing holding me back from finshing the game(right now anyway).
I dont know if this is a better way of asking, sorry ;6

By the way,
I have NO IDEA what an alpha test is.
Ive still got a lot to learn I know.

"For every answer, I have a question."
Heh, no problem.

In OpenGL, at least, enabling alpha testing only draws pixels to the screen that are over a certain opacity. The main problem with API controlled depth sorting in OpenGL and DirectX is that with alpha blended sprites (with various levels of opacity) must be drawn sorted from back to front or else the objects in back will disappear behind the alpha blended sprites in front, even though they're semi-transparent. This is because when the alpha-blended front sprites are drawn, they update the depth buffer and cause the API to cull the sprites behind them. If all you're using depth sorting for is to make alpha masks or something like that work properly, then you can use the alpha test to prevent modification of the z buffer in transparent areas so that the partially hidden sprites still appear. This is a terrible explanation, but if thats what you're doing this for, I reccomend further reasearch in this area. Alpha Testing

My best reccomendation is to group objects by location, like room or floor, and then cull/sort out these groups. From there, you can sort the individual objects in the current area in relation to the moveable characters and stuff.

Also, for depth sorting, you may wish to consider changing your method a bit. Instead of assigning integer incremental values as you are (1, 2, 3, etc.), make a consistant floating point z scale, and assign values with that. Create some formula to calculate the distance from the screen, and assign every object a z value. If you have a bookshelf, the player, and another bookshelf, they might have the z values of 6, 5.5, and 5, which would take care of the ordering issue. Then just sort by z value and draw. I would let the API handle this, but if you really want to, look into ordered lists, sorting functions, or the STL map.
Awesome, thats great info.
That makes it heaps easier. Thanks for going into depth.
"For every answer, I have a question."

This topic is closed to new replies.

Advertisement