Jump to content
  • Advertisement
Sign in to follow this  
RDK1LL

Z-Order for 2D Isometric game

This topic is 4422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Awesome, thats great info.
That makes it heaps easier. Thanks for going into depth.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!