Does DisplayObject have to be sealed?

Nov 3, 2011 at 10:48 AM

I want to implement a collection of objects that can be moved as a unit, as leaves on a tree. It's convenient to derive the leaves from Transformable and it would be natural to derive the nodes from DisplayObject (which seems to be the only Transformable that can hold a collection of objects) except that it's sealed. Is there any reason it has to be so?

If I implement my own collection it seems the objects won't appear in the scene tree and won't get drawn unless I implement that too.

Obviously there are other approaches such as using the Tag property or extension methods, but those approaches have other limitations.

 

 

 

Coordinator
Nov 3, 2011 at 10:52 AM
Hmmm, second thought, it doesn't have to be sealed.
Nov 7, 2011 at 11:58 AM

Another one: it's not possible to subclass TweenAnimation<> because lerp is private. It needs to be protected, or the default constructor in the subclass fails.

Coordinator
Nov 7, 2011 at 12:02 PM
Instead of making lerp protected, I prefer to expose a static mapping from type T and a lerp delegate.

I'm curious what type are you subclassing that is not included in the defaults?
Coordinator
Nov 8, 2011 at 12:45 AM

or you can use this constructor in your derived class, this works better.

public TweenAnimation(Interpolate<T> lerp, Operator<T> add)

Nov 8, 2011 at 1:11 AM

I was experimenting with a subclass of TweenAnimation<float>. Once the type T is known it's easier to write additional functions such as arithmetic calculations. The same would apply to a specialisation for Vector or Matrix.

As it is the constructor fails in GetType().GetField("lerp" because there is no lerp in the derived class. Making lerp protected simply makes the problem go away (but I'm sure there are other solutions). This was not the problem for which the other constructor was intended, and I'm still not sure how I would write it (bearing in mind that LerpHelper and AddHelper are not public).

If you have a solution in mind that avoids the whole Reflection thing that would be even better.

Coordinator
Nov 8, 2011 at 2:16 AM
Edited Nov 8, 2011 at 2:17 AM
I see your point, it should be a bug to use GetType().GetField. I think making it typeof(TweenAnimation<T>).GetField should solve the problem.