4

I have a heterogeneous FlxGroup contains: 10 FlxSprite and 4 FlxText. I add all objects with add(obj) function and their z-indexes determined by add function.

I want to change z-index values of objects in my FlxGroup dynamically while program is running (ex: With mouse click).

I tried things like:

  • this.setChildIndex(object, i) but there is no function like this
  • this.add(object) tried to add object which is already added
Enes F.
  • 309
  • 3
  • 13

1 Answers1

7

With FlxGroups, the "z-index" is nothing but the array position of the object within the FlxGroup's "members" array. So if you have some FlxGroup "mygroup" it would be simply a matter of changing where your object is in the array "mygroup.members".

EDIT: And to be perfectly clear, it draws in order from the first element to the last, so array position 0 is the "bottom" of the stack.

EDIT 2: Also, just an FYI: FlxState's use the exact same method with their "members" array / add()/remove() logic as well. They're basically glorified FlxGroups themselves.

larsiusprime
  • 935
  • 6
  • 14
  • Thanks Larsius! You helped me so much not only for this question but also previous questions. – Enes F. Dec 27 '15 at 20:36
  • No problem :) I just follow the Haxe StackOverflow twitter bot and answer questions when I can.... seems like 90% of them are HaxeFlixel questions, the one framework I happen to know anything about XD – larsiusprime Dec 27 '15 at 21:06