DrawTarget

May 24, 2009 at 6:47 AM

Hi!

How can I access to drawable childs of DrawTarget?

Thanks!

Coordinator
May 24, 2009 at 7:11 AM

There isn't any standard way. However you can always simply create an intermediate class (which will be common behavior anyway, if you want to be drawing things in a dynamic order then it's best to be handled in a separate class, etc).

May 24, 2009 at 8:51 AM

Can you add some readonly methods to define how much childs it have, and get child by index?

Thanks!

Coordinator
May 24, 2009 at 10:38 AM
Edited Oct 6, 2009 at 8:39 AM

I don't plan to do that.

There is nothing stopping you making a class something like:

class DrawList : IDraw
{
  IDraw[] items;
  
  public void Draw(DrawState state)
  {
    foreach (IDraw item in items)
    {
      if (item.CullTest(state))
        item.Draw(state);
    }
  }

  bool ICullable.CullTest(ICuller state)
  {
    return true;
  }
}

And adding an instance of that to the DrawTarget, then doing what you need in that class instead.

(Edited)

May 24, 2009 at 2:42 PM

OK,

Thanks for your help!

Oct 6, 2009 at 4:48 AM

I wrote a method:

public static List<IDraw> GetXenDrawTargetDrawList(DrawTarget target)
{
   Type targetType = target.GetType().BaseType;
    return (List<IDraw>)targetType.GetField("drawList", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(target);
 }

Can you add only ClearAllChildrens method? This is all that is needed.

Tkx!

Coordinator
Oct 6, 2009 at 8:38 AM
Edited Oct 6, 2009 at 8:42 AM

I wouldn't recommend doing this.


The best (and intended) way to deal with this situation is to use your own intermediate class. If you want to have very direct control of draw order, then it's best to implement that control yourself in a wrapper class. Very similar to what I posted just up above. That way you have complete control of the draw order and store your list however you want.