cocos2dx将cocos studio中导出的Json运行成动画

时间:2014-07-01 15:28:38

标签: c++ json animation cocos2d-x cocos2d-x-3.0

我试图从CocosStudio读取/加载导出的JSON和资源(这是一个生成动画的工具) 但是当我尝试加载或读取接缝时,任何类或函数都不能加载此文件。我做了一个网络研究,我发现的都是不推荐的代码或外部库等。 想是这样的:

auto animation animation =             extension::ccSkeletonAnimation::createWithFile("FILE.JSON","FILE.ATLAS");
animation->setPosition((x+y));
animation->setAnimation("a",true);
this->addChild(animation,0);

上面的代码使用类似于" cocosStudio"的外部工具,称为" Spin"

是否可以为此提供一些指导......?或者将动画设置为JSON文件的正确类? cocos2dx版本是3.1 提前致谢! 最好的问候!

1 个答案:

答案 0 :(得分:1)

我使用此代码将动画从cocostudio导入到visual studio 12

    cocostudio::Armature* armature;  
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("DemoPlayer0.png","DemoPlayer0.plist","DemoPlayer.ExportJson");
        armature = Armature::create("DemoPlayer");
        armature->setPosition(ccp(visibleSize.width * 0.8,visibleSize.height * 0.5));
        armature->getAnimation()->playByIndex(0);
        armature->setScale(0.25);
        this->addChild(armature);

或者您可以在cocostudio的帮助部分查看此代码。

//async loading export file
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Cowboy0.png","Cowboy0.plist","Cowboy.ExportJson");

//Creat armature by name
CCArmature *armature = CCArmature::create("Cowboy");

//play animation by animation index
armature->getAnimation()->playByIndex(0);

//Change Permissions
armature->setScale(0.5f);

//Set the armature position
armature->setPosition(200,300);

//add to the current scene
this->addChild(armature,2)
祝你好运!