SuperKef

Hello All,

I'm trying to make my code a bit more dynamic so I'm trying to get a list of attachments on a slot. Let's say the slot is called Clothes_Torso.
this.spine.skeleton.skin.getAttachmentsForSlot('Clothes_Torso')
The code above returns undefined. After reading the docs it says the code should be:
getAttachmentsForSlot (slotIndex: number, attachments: Array<SkinEntry>)
But why would i send along an array of attachments when that's what I want in the first place?

I hope this is somewhat clear?

Thank!

[EDIT] Oooooooh the attachments: Array<SkinEntry> is an out. The method itself returns nothing. How odd.
SuperKef
  • Beiträge: 1

Nate

The reason the method takes an array is that it adds the attachments to the provided array. This avoids allocation, which is sometimes important in games (though admittedly this particular method is unlikely to be called very often). Also you can more easily add attachments to an array without needing to copy them from one array to another.

Note you need to pass the slot index, not the name string. The index is on the SlotData, so:
var attachments = [];
this.spine.skeleton.skin.getAttachmentsForSlot(slot.data.index, attachments);
Or if you only have the name string:
var attachments = [];
var slotIndex = this.spine.skeleton.data.findSlot("slot name").index;
this.spine.skeleton.skin.getAttachmentsForSlot(slotIndex, attachments);
Benutzeravatar
Nate

Nate
  • Beiträge: 11845


Zurück zu Runtimes