Jump to content
  • Advertisement
Sign in to follow this  
Drakken255

XNA: Manually Sort by DrawOrder

This topic is 2570 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

Hey all,

Due to the fact that my code uses the ScissorRectangle to draw multiple objects, I can't use any SpriteSortMode except Immediate, but I still want them to be drawn in order. Thus, I have concluded that I need to manually sort the objects based on their DrawOrder. The problem lies in my current inability to think of a performance cheap sorting algorithm. By the way, I don't necessarily need a list to actually be sorted, but rather a collection of draws that are based on each object's DrawOrder. If presorting a list and then drawing is faster though, then let me know.

Share this post


Link to post
Share on other sites
Advertisement
Sort an array of indices such that each index represents one of your to-draw objects in a second array or sort an array of pointers (or whatever you have in C# that is similar) to your to-draw objects.
Use a bubble sort and keep the results of the last frame. While a bubble sort is slower on average than a quick sort, it is faster when objects are already sorted or nearly sorted, which your objects will be from frame-to-frame.


L. Spiro

Share this post


Link to post
Share on other sites
Thanks for your help, though I found a weird bit of code to help me instead: WindowList.Sort(delegate(Window w1, Window w2) { return w1.Layer.CompareTo(w2.Layer); });

Works well enough for me and doesn't seem to hurt my frame rate.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!