目前只够定了 不同套皮肤打在一个文件里的方式, 例如: 可以给只更换某个武器. 但是如果需要更换的皮肤特别多的话. 就会给内存带来压力. 求教如何加载一个外部的一个png图片更换.
网上有人实现了类似的, 原文地址:http://blog.csdn.net/n5/article/details/21795265
但是这个有一个致命问题就是无法设置新添加部件的层级. 只能在最后或者最前.
spine换装的需求应该很强烈吧. 但网上很少有类似的资料.
如何 new一个 attachment???用外部的 png图片












居然没人回答 唉
同样纠结。。。官方管绑不管用
顶一下~~~~
顶一下啊。楼主后来怎么样了?
帮你顶一下啊,
把当前hero remove
在相同 的position重新create
顶。。。。
目前spine没有提供换装的方法,需要自己去修改spine的源码来实现。之前的一个项目中有这方面的需求,试着实现了一下。方法直接加在类SkeletonRenderer中。
bool SkeletonRenderer::changeAttachment(const std::string& slotName, const std::string& attachmentName, const std::string& atlasFile)
{
spSlot * slot = this->findSlot(slotName);
if (NULL == slot)
{
return false;
}
int nType = slot->attachment->type;
spAtlas* atlas = createSpAtlasFromFile(atlasFile.c_str(), 0);
CCASSERT(atlas, "SkeletonRenderer::changeAttachment Error reading atlas file");
spAtlasAttachmentLoader* atlasAttachMentLoader = spAtlasAttachmentLoader_create(atlas);
spAttachmentLoader *attachmentLoader = &(atlasAttachMentLoader->super);
spSkin *skin = spSkin_create("default");
switch (nType)
{
case SP_ATTACHMENT_REGION:
{
spRegionAttachment* regionAttachmentSrc = (spRegionAttachment*)(slot->attachment);
spAttachment* attachment = spAttachmentLoader_newAttachment(
attachmentLoader, skin, SP_ATTACHMENT_REGION, slotName.c_str(), attachmentName.c_str());
//spAttachment* attachment = spAttachmentLoader_newAttachment(attachmentLoader, NULL, SP_ATTACHMENT_REGION, "role_weapon", "weapon_104005");
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);
slot->attachment = (spAttachment*)regionAttachment;
}
break;
case SP_ATTACHMENT_BOUNDING_BOX:
{
spBoundingBoxAttachment* boxAttachmentSrc = (spBoundingBoxAttachment*)(slot->attachment);
spAttachment* attachment = spAttachmentLoader_newAttachment(
attachmentLoader, skin, SP_ATTACHMENT_REGION, slotName.c_str(), attachmentName.c_str());
spBoundingBoxAttachment* boxAttachment = (spBoundingBoxAttachment*)attachment;
boxAttachment->verticesCount = boxAttachmentSrc->verticesCount;
boxAttachment->vertices = boxAttachmentSrc->vertices;
for (int i = 0; i < boxAttachmentSrc->verticesCount; i++)
boxAttachment->vertices* =boxAttachmentSrc->vertices*;
slot->attachment = (spAttachment*)boxAttachment;
}
break;
case SP_ATTACHMENT_MESH:
{
spMeshAttachment* meshAttachmentSrc = (spMeshAttachment*)(slot->attachment);
spAttachment* attachment = spAttachmentLoader_newAttachment(
attachmentLoader, skin, SP_ATTACHMENT_REGION, slotName.c_str(), attachmentName.c_str());
spMeshAttachment* meshAttachment = (spMeshAttachment*)attachment;
meshAttachment->rendererObject = meshAttachmentSrc->rendererObject;
meshAttachment->regionU = meshAttachmentSrc->regionU;
meshAttachment->regionV = meshAttachmentSrc->regionV;
meshAttachment->regionU2 = meshAttachmentSrc->regionU2;
meshAttachment->regionV2 = meshAttachmentSrc->regionV2;
meshAttachment->regionRotate = meshAttachmentSrc->regionRotate;
meshAttachment->regionOffsetX = meshAttachmentSrc->regionOffsetX;
meshAttachment->regionOffsetY = meshAttachmentSrc->regionOffsetY;
meshAttachment->regionWidth = meshAttachmentSrc->regionWidth;
meshAttachment->regionHeight = meshAttachmentSrc->regionHeight;
meshAttachment->regionOriginalWidth = meshAttachmentSrc->regionOriginalWidth;
meshAttachment->regionOriginalHeight = meshAttachmentSrc->regionOriginalHeight;
spMeshAttachment_updateUVs(meshAttachment);
slot->attachment = (spAttachment*)meshAttachment;
}
break;
case SP_ATTACHMENT_SKINNED_MESH:
{
spSkinnedMeshAttachment* skinnedAttachmentSrc = (spSkinnedMeshAttachment*)(slot->attachment);
spAttachment* attachment = spAttachmentLoader_newAttachment(
attachmentLoader, skin, SP_ATTACHMENT_REGION, slotName.c_str(), attachmentName.c_str());
spSkinnedMeshAttachment* skinnedAttachment = (spSkinnedMeshAttachment*)attachment;
skinnedAttachment->rendererObject = skinnedAttachmentSrc->rendererObject;
skinnedAttachment->regionU = skinnedAttachmentSrc->regionU;
skinnedAttachment->regionV = skinnedAttachmentSrc->regionV;
skinnedAttachment->regionU2 = skinnedAttachmentSrc->regionU2;
skinnedAttachment->regionV2 = skinnedAttachmentSrc->regionV2;
skinnedAttachment->regionRotate = skinnedAttachmentSrc->regionRotate;
skinnedAttachment->regionOffsetX = skinnedAttachmentSrc->regionOffsetX;
skinnedAttachment->regionOffsetY = skinnedAttachmentSrc->regionOffsetY;
skinnedAttachment->regionWidth = skinnedAttachmentSrc->regionWidth;
skinnedAttachment->regionHeight = skinnedAttachmentSrc->regionHeight;
skinnedAttachment->regionOriginalWidth = skinnedAttachmentSrc->regionOriginalWidth;
skinnedAttachment->regionOriginalHeight = skinnedAttachmentSrc->regionOriginalHeight;
spSkinnedMeshAttachment_updateUVs(skinnedAttachment);
slot->attachment = (spAttachment*)skinnedAttachment;
}
break;
default:
break;
}
return true;
}**
这个在setAnimation后 换装就无效了。你那有做什么特殊操作吗?
试试 可能能用