Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Order or 2D drawable entities


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Phenixer   Members   -  Reputation: 101

Like
0Likes
Like

Posted 23 June 2012 - 09:27 AM

Hey Guys,

I was asking myself what would be the best way to order my entities drawn on my map in 2D space.
What I actually do is Draw the map background, Draw all entities (pawns + projectiles) in a given order, Draw the map foreground.
For all my entities, I need to draw them in Y coordinate order.

I could :
1. Order every time I draw on screen, every tick I go trough the whole array (ordered) and reorder using a simple bubble sort and continue to cycle until nothing requires ordering.
2. Order directly in the classes when moving. If an entity moved, it requires reorder.

I do not know much about reordering techniques and I will surely (or maybe?) not use C# LinQ OrderBy method.

Thank you for answers !

Sponsor:

#2 SHilbert   Members   -  Reputation: 647

Like
0Likes
Like

Posted 23 June 2012 - 04:23 PM

Assuming you are working in C# since you mentioned avoiding LINQ. My first try would be this:

Collect all the entities that are onscreen into a List, and use List.Sort with a custom Comparison<T> method. Don't use bubble sort! If you Clear() and re-used the visible entity list instance every frame, you will not generate any unnecessary garbage this way.

I wouldn't try to do any schemes to sort only while entities move unless you can't get good enough performance this way, just because it is far simpler code to just sort right before rendering. In my experience you can sort a lot of objects this way and it will still be fast.

Edited by SHilbert, 23 June 2012 - 04:27 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS