之前看过好多有关骨骼动画换装的文章,虽然给予很大帮助,然而自己也是费了很大劲,最终也是自己解决了问题,我把自己的解决方式分享出来,希望对你有所帮助:
void changeArmatureBone( cocostudio::Armature * armature , const char* boneName , cocos2d::Node* node )
{
assert( armature );
assert( node );
using namespace cocostudio;
Bone* bone = armature->getBone( boneName );
assert( bone );
if( nullptr == bone )
{
return;
}
Bone *pBone = armature->getBone( boneName );
int currentIndex = pBone->getDisplayManager()->getCurrentDisplayIndex();
DecorativeDisplay *pDis = pBone->getDisplayManager()->getDecorativeDisplayByIndex( currentIndex );
cocos2d::Node *pDisNode = pDis->getDisplay();
node->setAnchorPoint( pDisNode->getAnchorPoint() );
pBone->addDisplay( node , currentIndex );
//pBone->changeDisplayWithIndex( currentIndex , true );
}
要注意的是,这个是分离出来的一个骨骼动画换装的方法,其中第一个参数是你要换的骨骼动画的原动画,第二个参数是要换的骨骼动画的名字,第三个参数是要替换的资源,不过要注意的第三个参数要以skin的对象的形式创建(Skin是sprite的子类)。
希望对大家有用,闲下来没事突然想吧之前的经验拿出来分享下,勿喷。