kwarn41

Hi,

How can i change the draw order at runtime ?

Many thanks for your help
kwarn41
Posts: 23

Pharan

Which runtime?

draw order is usually just a slot array (.drawOrder) in the Skeleton object.
If you change the order of the contents of the array, you change the order the slots are drawn. First ones are under, last ones are on top.
User avatar
Pharan

Pharan
Posts: 5275

decoamorim

In Unity?
Can you give an example how to change the order of an specific slot?
Developer/Founder at DCF Studios
http://www.studiosdcf.com/
Author of
Cruz Brothers[PS4 / STEAM] [upcoming on XboxOne] - http://www.cruzbrothersgame.com
Bunny Battle Arena[STEAM] - https://store.steampowered.com/app/872340/Bunny_Battle_Arena/
User avatar
decoamorim
Posts: 123

Pharan

I think this method will work.
/// <summary>
/// Moves a given slot in the drawOrder. drawOrderOffset is the number of places to move the slot in the draw order. Positive values means the slot is drawn later.
/// </summary>
public static void MoveDrawOrder (Skeleton skeleton, string slotName, int drawOrderOffset) {
Slot slot = skeleton.FindSlot(slotName);
if (slot == null) return; // Do nothing if slot is not found.
var drawOrder = skeleton.DrawOrder;

int oldIndex = drawOrder.IndexOf(slot);
int newIndex = oldIndex + drawOrderOffset;
if (newIndex < 0) {
newIndex = 0;
} else if (newIndex > drawOrder.Count - 1) {
newIndex = drawOrder.Count - 1;
}

drawOrder.RemoveAt(oldIndex);
drawOrder.Insert(newIndex, slot);
}
User avatar
Pharan

Pharan
Posts: 5275

decoamorim

Thanks Pharan! =)
Developer/Founder at DCF Studios
http://www.studiosdcf.com/
Author of
Cruz Brothers[PS4 / STEAM] [upcoming on XboxOne] - http://www.cruzbrothersgame.com
Bunny Battle Arena[STEAM] - https://store.steampowered.com/app/872340/Bunny_Battle_Arena/
User avatar
decoamorim
Posts: 123

oseph

Bump!

Leaving a comment here because thanks for that snippit of code, Pharan!
oseph
Posts: 5


Return to Runtimes