• Runtimes
  • Managing hundreds of slots/attachments on one skeleton

Related Discussions
...

I've been using Spine and the TK2D runtime for a few weeks now, the artists on my team have for much longer. As we continue to add features to our game, animations to our character, and different things he can wear/carry it is becoming apparent that we are going to hit a few walls.

It initially looked like we would use a different attachment on a weapon or armor slot for each piece of equipment. We want some weapons to use multiple images so as they animate they show different angles of the weapon. An attachment can contain at most one image, so this won't work. We will have to use a different slot for each piece of equipment. Were we switching between attachments, it would be easy to just "SetAttachment" when things changed, but something similar doesn't exist for slots. The only way I can see to do it in the runtime is to go through each slot and set their attachment to null and set the one slot we want visible to have a non-null attachment.

That's one issue.

The other problem I foresee is with having several hundred potentially equippable weapons, clothing, and items (some of which animate). Aside from it making the skeleton HUGE, its going to have a vast library of images that will all need to be in a single sprite sheet. This won't really work.

I am considering solutions to these problems and what I have come up with is what I described above: a slot per equipment and setting all but one slot to null to change which one is shown; and extending spine runtime to manage multiple sprite sheets. (i.e. viewtopic.php?f=3&t=473&hilit=one+atlas )

Are these the correct/best approaches to these problems? Has anyone else dealt with this before?

Is there a strategy or method to attach things (bones, slots, other skeletons) to a skeleton at runtime?

Thanks!

aaron wrote

We want some weapons to use multiple images so as they animate they show different angles of the weapon. An attachment can contain at most one image, so this won't work. We will have to use a different slot for each piece of equipment.

You'll need a slot for each angle you want to show, not each weapon.

The other problem I foresee is with having several hundred potentially equippable weapons, clothing, and items (some of which animate). Aside from it making the skeleton HUGE, its going to have a vast library of images that will all need to be in a single sprite sheet.

You can use an atlas with multiple pages. Note that this will cause additional texture binds, but you can minimize this by packing images drawn together on the same atlas page. Eg, you could have an atlas page with all the character images, and another with all the weapons. This could result in a bind for the character images, a bind for the weapon, and a bind for the rest of the character images. Of course you could have more binds depending on your attachments. If you are targeting desktop it isn't much of an issue. On mobile if you have only a few characters where you do this you could be alright.

Is there a strategy or method to attach things (bones, slots, other skeletons) to a skeleton at runtime?

You can have an application specific data structure (eg, maybe a JSON file) that describes what attachments make up a weapon. Or, maybe you use a naming convention. Either way, you then just set the attachments.

To make your attachment changes reusable with animations, you can use skins. You have a skin for "machine gun" and you define the attachments for each angle (normal, tilted1, tilted2, or whatever) using skin placeholders. Then you have another skin "laser gun" and you do the same. Now in animations you can change which view of the weapon is shown, without actually knowing if it is a machine gun, laser gun, or something else.

You can use this approach for multiple parts of your character. Eg, say you want to use skins for how your character looks, but also use skins for your weapons. At runtime, a skeleton can only have a single skin, however you can programmatically create a skin. You can then take two skins and combine them into one at runtime, and use that for your skeleton. In this way you can mix and match skins to get the look you want, and all your animations will work even if they have attachment change keys. Currently Spine only allows a single skin to be visible in the editor. This makes it harder to preview in the editor, but still works fine at runtime.

3달 후

Hey Nate, could you elaborate a little on how to combine skins at runtime? some example code or pointing in the right direction would be great.

A skin is just a map where the key is slot index + name and the value is an attachment. You need to create a new skin, then iterate through the entries of other skin, adding the entries to your new skin. I'd like to add a method to do this to all the runtimes.

3달 후

Hi Nate,
Is there a method to do this mix and match of skins in any of the runtimes?

knish, there isn't a method to do it, but here is what it looks like in libgdx:

SkeletonData skeletonData = ...
Array<SlotData> slots = skeletonData.getSlots();
Skin newSkin = new Skin("new skin");
// To add all the attachments for a skin to newSkin:
Skin skin = skeletonData.findSkin("other skin");
Array<String> names = new Array();
for (int slotIndex = 0; slotIndex < slots.size; slotIndex++) {
   names.clear();
   skin.findNamesForSlot(slotIndex, names);
   for (String name : names) {
      Attachment attachment = skin.getAttachment(slotIndex, name);
      newSkin.addAttachment(slotIndex, name, attachment);
   }
}

It would be nice if Skin had a method to do this, it just needs to be added to all the runtimes and tested. Task:
https://trello.com/c/wfMAxiV5/65-method ... to-another