0

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?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Lea Hayes
  • 62,536
  • 16
  • 62
  • 111

2 Answers2

3

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.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Jorjon
  • 5,316
  • 1
  • 41
  • 58
  • Thanks, I wasn't aware of the `DisplayObjectContainer` class. The only reason I have **Game** is because that was automatically generated by the tool that I am using, though by default it is named **Main**. I suspect that it would be better to derive that from `DusplayObjectContainer` also. I will experiment with that. – Lea Hayes Aug 13 '13 at 22:02
1

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).

Liosan
  • 7,520
  • 2
  • 17
  • 16