Make FlxText into a FlxNestedSprite
I'm trying to create a version of FlxText that I can use as a nested sprite. Since FlxText already inherits from FlxSprite, it seems like this should be easy. However, I'm not sure how to do it. A bad way to do it would be to copy everything from FlxText.hx and have it extend FlxNestedSprite instead of FlxSprite. Is there a way to simply cast a FlxSprite as a FlxNestedSprite?
No, there's no simple way of doing that due to how inheritance works. And the hierarchy in this case looks like this:
FlxSprite / \ / \ / \ FlxText FlxNestedSprite
There's no way to join those two branches together again, since Haxe (and most other languages that support OOP) don't support multiple inheritance.
What you could try is have a
extends FlxNestedSprite, but has a reference to a
FlxTextinstance (and override some
FlxNestedSpritemethods to call
FlxTextmethods instead in relevant places). It's not a pretty solution either, and it's similar to what
FlxSpriteGroupdoes (inherits from
FlxSprite, but has a
Thanks, that's what I figured. I had hoped there was a simple workaround since the FlxSprite and FlxNestedSprite APIs are so similar.