Cocos2d-x的骨骼动画Spine和Armature

前端之家收集整理的这篇文章主要介绍了Cocos2d-x的骨骼动画Spine和Armature前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

cocos2d-x中骨骼动画常用的有2种,spine和armature


Spine的基本用法

  1. //骨骼动画Spine,需要包含Spine/spine-cocos2dx.h头文件,命名空间spine
  2. auto skeleton=SkeletonAnimation::createWithFile("spine/spineboy.json","spine/spineboy.atlas");//加载文件
  3. skeleton->setAnimation(0,"walk",false);//运行骨骼动画,参数:(什么意思?,动作名,是否循环播放)
  4. skeleton->setPosition(500,0);
  5. skeleton->setScale(0.5f);//设置大小
  6. skeleton->setTimeScale(0.5f);//设置运行速度
  7. skeleton->setMix("walk","run",1.0f);//设置动画平缓切换用时
  8. skeleton->addAnimation(0,true);//在之前动作做完之后,添加一个动作
  9. skeleton->setDebugBonesEnabled(true);//显示骨头
  10. this->addChild(skeleton);


Armature的基本用法

  1. //骨骼动画armature,需要包含cocostudio/CocoStudio.h头文件,命名空间cocostudio
  2. //加载动作资源,可以用异步加载,参数有点怪
  3. ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Cowboy0.png","armature/Cowboy0.plist","armature/Cowboy.ExportJson");
  4. auto am=Armature::create("Cowboy");//创建骨骼动画
  5. am->setScale(0.6f);
  6. am->getAnimation()->setSpeedScale(0.5f);//设置播放速度
  7. am->getAnimation()->playWithIndex(0);//播放索引为0的动作
  8. am->setPosition(500,300);
  9. this->addChild(am);

猜你在找的Cocos2d-x相关文章