First of I am using the LibGDX setup.
I have the following setup:
- Skeleton used for all characters
- Outfits defined as seperated image files
- Template skin loaded as part of the animation
- Custom skins are created on runtime for each outfit
- It doesnt work - and I am getting frustrated
First thing I do is:
A. Extract my 'template' skin
B. Create a 'custom' skin by creating a copy of my 'template' skin
C. Clone the RegionAttachments of the custom skin and reassign TextureRegions to match the desired outfit
Already at B, I have an issue. The resulting skin is empty after I run skeleton.setSlotsToSetupPose()..
public void copySkinTo( Skin template, Skin copy ) {
Array< Attachment > attachments = new Array<>();
for( int index = 0; index < slotNames.length; index++ ){
String slotName = slotNames[ index ];
attachments.clear();
template.findAttachmentsForSlot( index, attachments );
if ( attachments.size != 1 ) {
throw new IllegalStateException( "Template must have one attachment per slot, had " + attachments.size + " on slot " + slotNames[ index ] );
}
copy.addAttachment( index, slotName, attachments.first() );
}
}
This article (Runtime Skins - Spine Runtimes Guide: Customization) suggests a similar approach, but does not mention how to create copies of the template... I assume I am not supposed to load the same skeleton once for each character. Been hacking at this problem for 1-2 weeks now, with no solution. 🙁