Sign in to follow this  
Zeke

ID3DXSprite Depth Sorting

Recommended Posts

Zeke    122
I am drawing a bunch of sprites to the screen, is there anyway I can control the order they are drawn without giving each one a z value? For e.g. I have a background image of a game board and a marker that is moving around said board. I draw the background first, then the marker. But sometimes the background is drawn first, which is what I want, but sometimes the marker is drawn first and then the background is drawn obscuring it, even though ive checked to make sure the call to ID3DXSprite::Draw is done for the background first every time. I can get around this by giving each sprite its own z position and making sure the marker has a z position in front of the background. But it seems daft having z values of 1,2,3,4... when they are all flat images and all I really need to do is make sure the "top" sprites are drawn after the "bottom" sprites. Any ideas?

Share this post


Link to post
Share on other sites
ChaosPhoenix    242
Interesting.

I've never had this issue occur when I used sprites. Are you sure you have the depth buffer turned off? You might be experiencing some Z fighting otherwise...

The solution you've come up with is pretty typical in most sprite engines. You simply give each sprite a draw priority(a Z value in your case) and then draw from back to front. There's nothing really wrong with your approach but I can see why you might find this solution annoying.

Turns out ID3DXSprite's Begin method also accepts a flag of "D3DXSPRITE_SORT_DEPTH_BACKTOFRONT" so you can make sure that your sprites are being drawn in the correct order if you are using a Z value.

But, yea, make sure your depth buffer (D3DRS_ZBUFFER is the render state flag I believe, just set it to false through SetRenderState) is disabled and see if that helps.

Share this post


Link to post
Share on other sites
Zeke    122
Thanks for the info ChaosPhoenix, ive got the depth buffer turned on but I need it on because im mixing 2d sprites and 3d objects. Come to think of it, I only noticed the problem once I turned it on (I got the 2d stuff working first so didnt have the depth buffer turned on).

But ill have to put up with giving each sprite a z value even if it does seem a bit odd. As long as there isnt anything wrong with doing that :)

Cheers

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