# Sprite Z-Order

## Recommended Posts

Beginner question... how do I go about setting the z-order for sprites being positioned with a D3DVECTOR2 position? I know a D3DVECTOR3's z parameter will be used as depth, but I'm doing 2D matrix transformations and can't use the third parameter. Or would prefer not to use it, anyway, since it'd muck up my stuff.

##### Share on other sites
streamer    415
turn off z-buffer, draw your sprites in whatever order you need, and turno on z-buffer. It is that simple[smile]

##### Share on other sites
Okay, well then I'm still stuck. I'm trying to sort all the sprites by their distance to the camera, so I can draw them in the correct order. Of course it's being a pain and not working.

In my render function, I stuffed the sprite info into a vector:

std::sort(spriteSort.begin(), spriteSort.end(), compare);

The compare function:

bool compare(spriteInfo* a, spriteInfo* b) {    return a->distToCamera < b->distToCamera;}

I ran debug on it, the compare function is being called. There are no errors or warnings. Everything is supposed to be perfect. But it's not sorting. I run through the vector afterward, and it's like I didn't even call sort. It does nothing to it.

Uh... what?