I would like to change the draworder ( aka the order in which the different slots [= images] are drawn in game), based on
some event in the code. E.g. when the user presses a button, move one of the slots to the very top, when the button is released, move it to the bottom again. ( It's a bit more complicated than that because there's also a bone that is changing position. This example is mainly to illustrate the way I want to change the drawOrder).
I can't do it via an animation keyframe since the change to the drawOrder should happen based on user input.
I was looking at
internal List<Slot> drawOrder;
in Skeleton.cs. It seems the way to do it is to change the skeleton's drawOrder.
In Animation.cs around line 533 there's this:
List<Slot> drawOrder = skeleton.drawOrder;
List<Slot> slots = skeleton.slots;
int[] drawOrderToSetupIndex = drawOrders[frameIndex];
if (drawOrderToSetupIndex == null) {
drawOrder.Clear();
drawOrder.AddRange(slots);
} else {
for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++)
drawOrder[i] = slots[drawOrderToSetupIndex[i]];
}
Since I didn't find anything I'm gonna start hacking around with this, trying to change the drawOrder list. If anyone has a great idea in the meantime that'd be greatly appreciated 🙂
==================================================================
Below this line was from my 2nd post. Looks a bit weird in an auto-merged post
Alright, so I'm gonna answer myself 8) in the hopes that this helps other ppl..
Looks like you can simply change
skeleton.drawOrder
.
drawOrder is a list of Slots.
You could for instance define different "order lists" in your constructor like so:
var background = skeletonAnimation.skeleton.FindSlot("background");
var tree = skeletonAnimation.skeleton.FindSlot("tree");
var swiper = skeletonAnimation.skeleton.FindSlot("swiper");
var drawOrderFromSpine = new List<Spine.Slot>(skeletonAnimation.skeleton.DrawOrder);
var swiperInFrontOfTree = new List<Spine.Slot>() { background, tree, swiper };
var swiperBehindTree = new List<Spine.Slot>() { background, swiper, tree };
And then, during the game e.g. in Update or wherever, update the drawOrder property of the skeleton:
var drawOrder = skeletonAnimation.skeleton.DrawOrder;
if (isSwiperBehindTree)
{
drawOrder.Clear();
drawOrder.AddRange(swiperBehindTree);
}
else {
drawOrder.Clear();
drawOrder.AddRange(swiperInFrontOfTree);
}
Alternatively the drawOrder List could also be just sorted via drawOrder.Sort(...) .
This seems to work. As long as you don't have any keyframed changes to the drawOrder.
Any comments? Just wondering if this is "the way" since I didn't find anything in the docs.