Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change z-index of the FlxSprite in FlxGroup?

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
like image 964
Enes F. Avatar asked Mar 14 '23 18:03

Enes F.


1 Answers

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.

like image 105
larsiusprime Avatar answered Apr 10 '23 01:04

larsiusprime