骨骼动画 cocos2d-x + cocoStudio <cocos2d-x : version 2.2.0>
cocos2d-x version 2.2.0
首先,在 HelloWorldScene.cpp 中的 init()函数中 添加如下代码 (资源文件可以直接到 cocos2d-x 中获取)
#include "CCArmature/utils/CCArmatureDataManager.h" //(头文件添加)
//! create a new thread to load data(异步加载)
/**
* @brief Add ArmatureFileInfo, it is managed by CCArmatureDataManager.
* It will load data in a new thread
* 添加ArmatureFileInfo,它是由CCArmatureDataManager管理。 它将数据加载在一个新线程
*/ extension::CCArmatureDataManager::sharedArmatureDataManager()
->addArmatureFileInfoAsync("cyborg.png", "cyborg.plist", "cyborg.xml", this, NULL/*schedule_selector(TestArmatureNesting::close)*/); CCLayer *pLayer = new TestArmatureNesting();
this->addChild(pLayer);
其次,TestArmatureNesting 类实现
//.h
class TestArmatureNesting : public cocos2d::CCLayer
{
public:
virtual void onEnter();
virtual void onExit();
virtual bool ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
virtual void registerWithTouchDispatcher(); void close(float percent); cocos2d::extension::CCArmature *armature;
int weaponIndex;
}; //.cpp
void TestArmatureNesting::onEnter()
{
CCLayer::onEnter();
setTouchEnabled(true);//触摸事件开启 与registerWithTouchDispatcher() 对应
armature = cocos2d::extension::CCArmature::create("cyborg");
/** playByIndex()
* Play animation by index, the other param is the same to play.
* @param _animationIndex the animation index you want to play
*/
armature->getAnimation()->playByIndex();
armature->setPosition(ccp(,));
armature->setScale(1.2f);
armature->getAnimation()->setSpeedScale(0.4f);
addChild(armature); weaponIndex = ;
} void TestArmatureNesting::onExit()
{
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
CCLayer::onExit();
} bool TestArmatureNesting::ccTouchBegan( CCTouch *pTouch, CCEvent *pEvent )
{
++weaponIndex;
weaponIndex = weaponIndex % ; /** virtual CCBone *getBone(const char *name) const;
* Get a bone with the specified name
*
* @param name The bone's name you want to get
*/
if(armature != NULL)
{
armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex);
armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex);
} return false;
} //registerWithTouchDispatcher() 注册触摸事件(触摸事件) -1>0 先触发
void TestArmatureNesting::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN + , true);
} void TestArmatureNesting::close(float percent)
{ }
点击屏幕 切换装备:(如图)



打开 .json 或者 .xml 文件我们会发现 一个动作的组成结构:
<mov name="fall" dr="5" to="6" drTW="5" lp="1" twE="NaN">
…… …… …… ……
</mov>
表示一个动作
这也就是 armature->getAnimation()->playByIndex(1); 这里的参数 1 的由来。
骨骼动画 cocos2d-x + cocoStudio <cocos2d-x : version 2.2.0>的更多相关文章
- cocostudio 骨骼动画 setContentScaleFactor
最近在看骨骼动画,看上去挺容易的,但是照着例子做的时候却出现问题了,骨骼之间出现了很大的缝隙,找了很久才发现原来setContentScaleFactor的原因, 出现间隙,是因为各个骨骼是单独在做缩 ...
- cocos2dx骨骼动画Armature源码分析(三)
代码目录结构 cocos2dx里骨骼动画代码在cocos -> editor-support -> cocostudio文件夹中,win下通过筛选器,文件结构如下.(mac下没有分,是整个 ...
- cocos2d-x 3.0 版本 骨骼动画设置shader
因为骨骼动画是由多个sprite组成, 所以需要遍历每个sprite 才能修改整体, 开头这样设置,在游戏中发现走路状态没问题,攻击状态就有部分sprite没效果 for (auto & ob ...
- cocos2dx - v2.3.3编辑器骨骼动画
接上一节内容:cocos2dx - v2.3.3编辑器简单使用及不同分辨率适配 本节主要Cocos骨骼动画的创建及使用 一.新建 用Cocos Studio工具新建一个状态栏项目.如下图: 当然也可以 ...
- cocos2dx加载骨骼动画,获取骨骼位置
2015/05/13 需求: (1)希望在骨骼上绑定一个粒子特效 (2)获取骨骼的位置 (3)获取骨骼动画的大小 (4)lua 1. cocostudio动画编辑器 (1)绑定粒子特效(跟随骨骼的移动 ...
- cocos2dx骨骼动画Armature源码分析(一)
源码分析一body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-to ...
- HTML5骨骼动画Demo | 使用min2d、createjs、pixi播放spine动画
Spine做骨骼动画是比较流行的,使用起来可能相对复杂,但功能毕竟强大,所以市场占有率较大. 在unity.cocos2d.starling中使用spine已经很成熟了,而HTML5这一块可能刚刚起步 ...
- cocos2d-x开发记录:二,基本概念(骨骼动画)
九,骨骼动画 1.骨骼动画vs Sprite sheets 你能使用sprite sheets 创建动画,它很快又容易.直到你意识到你的游戏需要大量的动画并且内存消耗越来越高,并且需要时间载入全部数据 ...
- 初尝2D骨骼动画编辑工具SPINE,并into Unity3D
一.SPINE使用 研究2D骨骼动画,CYou的朋友介绍我SPINE这个工具,开发自Esoteric Software的一款专门制作2D动画的软件,网络上的资料还很少,我这从半吊子美术技术的角度简单说 ...
随机推荐
- java上机
package wordcont; import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayLi ...
- 05 Spring框架 依赖注入(二)
上一节我们讲了三种信息的注入,满足一个类的属性信息的注入,但是如果我们需要向一个实例中注入另一个实例呢?就像我们创建一个学生类,里边有:姓名,性别,年龄,成绩等几个属性(我习惯把类的域叫做属性),但是 ...
- 从yum源下载软件包
以下是从163源下载openstack-ocata版软件包的脚本: from html.parser import HTMLParser from urllib import request impo ...
- Openstak(M版)计算节点安装
#############修改hosts文件 10.0.0.11 controller10.0.0.31 compute110.0.0.32 compute210.0.0.41 block110.0. ...
- 寻找最大(小)的K个数
<<编程之美>>一书中提到了寻找最大的K个数的问题,问题可以简单描述为:在长度为N的数组中,寻找第K(K<N)个最大的数.问题的解法涉及到了很多排序算法,对我们理解和运用 ...
- PAT 天梯赛 L1-029. 是不是太胖了 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-029 AC代码 #include <iostream> #include <cstdio&g ...
- Spring AOP 学习(一) 代理模式
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程(也叫面向方面),可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- IPU VPU GPU的关系
转:https://blog.csdn.net/dragon101788/article/details/78404669 Video graphics system[IPU, VPU and GPU ...
- Python编程-多线程
一.python并发编程之多线程 1.threading模块 multiprocess模块的完全模仿了threading模块的接口,二者在使用层面,有很大的相似性,因而不再详细介绍 1.1 开启线程的 ...
- Windows batch: call more than one command in a FOR loop?
https://stackoverflow.com/questions/2252979/windows-batch-call-more-than-one-command-in-a-for-loop U ...