就是获取bone节点, 然后添加 addDisplay 数据.调用 changeDiplayByIndex,将bone切到想要的数据节点上.就实现了动画的换装.
代码如下: 图片动画素材可以到这里获取 https://github.com/2youyouo2/CSArmature (fish.plist 是自己的测试图片)
- CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Cowboy","", "Cowboy0.png","Cowboy0.plist", "Cowboy.json");
- CCArmatureDataManager::sharedArmatureDataManager()->addSpriteFrameFromFile("fish.plist", "fish.png");
- //这种方式不可用,必须上面的方式将要替换的图片素材添加到spriteFrameCache中.这里花了很长时间.
- //CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fish.plist");
- CCArmature* armature1 =CCArmature::create("Cowboy");//读取Armature_data
- CCBone* bone = armature1->getBone("Layer136");
- CCSpriteDisplayData displayData;
- displayData.setParam("fish09_01.png");
- bone->addDisplay(&displayData, 1);
- bone->changeDisplayByIndex(1, true);
- armature1->setAnchorPoint(ccp(-0.5, 0));
- armature1->setScale(0.4);
- addChild(armature1);
- armature1->getAnimation()->playByIndex(1);/