Question

I am experimenting with Haxe and OpenFL and am wondering if the Sprite class is synonymous with a GameObject in Unity. It seems that sprite instances have a hierarchical structure and I am wondering if this can be utilised to manage objects.

For example:

Game (Sprite / container / no visual representation)
 |--> Grid (Sprite / container / no visual representation)
       |--> Tile (Sprite)
       |--> Tile (Sprite)
       |--> ...
 |--> ...

Am I correct with the above assumption, or should the Sprite class be extended purely for objects with visual representation?

Was it helpful?

Solution

If you only need a container, you should extend DisplayObjectContainer. But for abstract things like Game, I wouldn't use a DisplayObject at all, but custom classes.

Use classes extending from DisplayObject only for things that should be added to the Display List. In your example, Game shouldn't be a Sprite, but Tile and Grid probably yes.

OTHER TIPS

Well, I use that in my project, so probably the answer is 'yes' :)

In particular I use a grid with N horizontal sprites, so my isometric map is rendered in proper top-to-bottom order. I also use a single container for my HUD etc.

There are some caveats to this approach - "invisible" sprites cannot capture mouse events, and they cannot have their width/height set programmatically (only by adding children at appropriate positions).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top