Spine的基本用法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13//骨骼动画Spine,需要包含Spine/spine-cocos2dx.h头文件,命名空间spine auto skeleton=SkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas");//加载文件 skeleton->setAnimation(0, "walk", false);//运行骨骼动画,参数:( 动作例表id(从0开始),动作名,是否循环播放) skeleton->setPosition(500,0); skeleton->setScale(0.5f);//设置大小 skeleton->setTimeScale(0.5f);//设置运行速度 skeleton->setMix("walk", "run", 1.0f);//设置动画平缓切换用时 skeleton->addAnimation(0, "run", true);//在之前动作做完之后,添加一个动作 skeleton->setDebugBonesEnabled(true);//显示骨头 this->addChild(skeleton); spBone * skele= skeleton->findBone("jinyumantangdagaung"); //获取龙骨节点名称
skeleton->setEndListener([=](int trackIndex) {
if (trackIndex == 1) //播放次数,
{
//回调需要的
}
});
Armature的基本用法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22//骨骼动画armature,需要包含cocostudio/CocoStudio.h头文件,命名空间cocostudio //加载动作资源,可以用异步加载,参数有点怪 ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.ExportJson"); auto am=Armature::create("Cowboy");//创建骨骼动画 am->setScale(0.6f); am->getAnimation()->setSpeedScale(0.5f);//设置播放速度 am->getAnimation()->playWithIndex(0);//播放索引为0的动作 am->setPosition(500,300); this->addChild(am); am->getAnimation()->pause(); //播放 std::function<void(Armature*, MovementEventType, const std::string&)> armatureFun = [=](Armature* armature, MovementEventType type, const std::string& id) { if (type == MovementEventType::COMPLETE && id == "Animation4") { animationEvent(true); am->getAnimation()->stop(); } }; am->getAnimation()->setMovementEventCallFunc(armatureFun); //回调
最后
以上就是悲凉太阳最近收集整理的关于Cocos2d-x的骨骼动画龙骨Spine和Armature的全部内容,更多相关Cocos2d-x内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复