void HelloWorld::changeAttachment(SpineNode* spineNode,const char *atlasAttachment, const char *replacedAttachment,const char *replaceAttachment){ spSlot* slot = spineNode->findSlot(replacedAttachment); if (NULL != slot) { int nType = slot->attachment->type; spAtlas* atlas = spAtlas_createFromFile(atlasAttachment, nullptr); CCASSERT(atlas, "SkeletonRenderer loading atlas file error"); spAtlasAttachmentLoader* atlasAttachmentLoader = spAtlasAttachmentLoader_create(atlas); spAttachmentLoader* attachmentLoader = &(atlasAttachmentLoader->super); spSkin *skin = spSkin_create("default"); spRegionAttachment* regionAttachmentSrc = (spRegionAttachment*)(slot->attachment); spAttachment* attachment = spAttachmentLoader_newAttachment( attachmentLoader, skin, SP_ATTACHMENT_REGION, replacedAttachment, replaceAttachment); spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment; regionAttachment->width = regionAttachmentSrc->width; regionAttachment->height = regionAttachmentSrc->height; regionAttachment->rotation = regionAttachmentSrc->rotation; regionAttachment->x = regionAttachmentSrc->x; regionAttachment->y = regionAttachmentSrc->y; regionAttachment->scaleX = regionAttachmentSrc->scaleX; regionAttachment->scaleY = regionAttachmentSrc->scaleY; regionAttachment->a = regionAttachmentSrc->a; regionAttachment->b = regionAttachmentSrc->b; regionAttachment->r = regionAttachmentSrc->r; regionAttachment->g = regionAttachmentSrc->g; spRegionAttachment_updateOffset(regionAttachment); spineNode->replacementPart(slot,attachment); //spineNode->replacementPart("shi_01_01_01_002",attachment); } }
static spSkin *readSkin(spSkeletonBinary *self, const char *skinName) { spSkin *skin; int slotCount = readVarint(self, true); if (slotCount == 0) { return NULL; } skin = spSkin_create(skinName); for (int i = 0; i < slotCount; i++) { int slotIndex = readVarint(self, true); int nn = readVarint(self, true); for (int ii = 0; ii < nn; ii++) { char *name = readString(self); spAttachment *attachment = readAttachment(self, skin, slotIndex, name); spSkin_addAttachment(skin, slotIndex, name, attachment); } } return skin; }