Skip to content

Instantly share code, notes, and snippets.

@pharan
Created May 16, 2017 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pharan/cc26dd3dd99a6bee8564020a50e936cd to your computer and use it in GitHub Desktop.
Save pharan/cc26dd3dd99a6bee8564020a50e936cd to your computer and use it in GitHub Desktop.
Spine 3.4 - 3.6 DrawOrder change method(s).
/// <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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment