I am new to spine and I was having some issue with skins using cocos2dx. What I want to do is to combine a skin with one or more other skins. I have tried to set each attachment individually from the two skins using the set attachment function, but that did not work. What I did with that method is that I gave it the slot name and the attachment name that was used in the atlas. The big issue that I see is that the base skin doesn't know about the slots that the attachments fit into. For example, the base skin has a right hand slot. The attachment that we want to give the base skin is a weapon that goes into the right hand. The slot for the weapon does not exist on the base skin.
This is how we figured out how to do it:
spSkin *baseSkin = spSkeletonData_findSkin(player1Node->getSkeleton()->data, "base_robber");
spSkin *subSkin = spSkeletonData_findSkin(player1Node->getSkeleton()->data, "robber_2");
spSkin *sub2Skin = spSkeletonData_findSkin(player1Node->getSkeleton()->data, "weapon_nunchaku");
for(int i = 0; i < player1Node->getSkeleton()->slotsCount; ++i) {
spSlot* slot = player1Node->getSkeleton()->slots[i];
if (slot->data->attachmentName) {
spAttachment* baseAttachment = spSkin_getAttachment(baseSkin, i, slot->data->attachmentName);
spAttachment* subAttachment = spSkin_getAttachment(subSkin, i, slot->data->attachmentName);
spAttachment* sub2Attachment = spSkin_getAttachment(sub2Skin, i, slot->data->attachmentName);
if (subAttachment) {
spSlot_setAttachment(slot, subAttachment);
}
else if (sub2Attachment) {
spSlot_setAttachment(slot, sub2Attachment);
}
else if(baseAttachment) {
spSlot_setAttachment(slot, baseAttachment);
}
}
}
Is there an easier way to do this?