做个小骨骼动画demo给大家试试先。
设置一个加载的label
CCLabelTTF *l = CCLabelTTF::create("0.0", "Arial", 50); l->setColor(ccColor3B(ccBLUE)); addChild(l, 1, 10001); l->setPosition( CCPoint(visibleSize.width/2, visibleSize.height - 60) );异步骨骼动画数据加载
//自己的骨骼动画 CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("test/BZ.ExportJson", this, schedule_selector(HelloWorld::dataLoaded)); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("test/JuRen.ExportJson", this, schedule_selector(HelloWorld::dataLoaded)); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("test/3.ExportJson", this, schedule_selector(HelloWorld::dataLoaded)); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("test/JR.ExportJson", this, schedule_selector(HelloWorld::dataLoaded));编写回调函数
void HelloWorld::dataLoaded( float percent ) { CCLabelTTF *label = (CCLabelTTF *)getChildByTag(10001); if (label) { char pszPercent[255]; sprintf(pszPercent, "%s %f","W_W", percent * 100); label->setString(pszPercent); } if (percent >= 1 && backItem&& nextItem) { backItem->setEnabled(true); nextItem->setEnabled(true); } }等回调完后就可以调用产生骨骼动画了
如下
CCArmature *armature = NULL; armature = CCArmature::create("JuRen"); armature->getAnimation()->playByIndex(1); armature->setPosition(CCPoint(300, 300)); addChild(armature);这样就成功能看到骨骼动画了