骨骼动画 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动画的软件,网络上的资料还很少,我这从半吊子美术技术的角度简单说 ...
随机推荐
- STM32 ~ CH340在STM32实现一键下载电路
在做基于STM32的多功能MP3播放器的课题时,在程序下载这部分时借鉴了正点原子开发板上的一键下载电路,采用CH340G这款芯片设计. 在画PCB初期原理图部分,对采用CH340G设计的一键下载电路不 ...
- loadrunder之脚本篇——action分类
Action分类 l . Vuser_init 2. Vuser_end 3. Action 在lr中用户的初始化操作应该存放在Vuser_init中.用户的结束操作存放在Vuser_end中.因为 ...
- $python正则表达式系列(2)——re模块常用函数
本文主要介绍正则re模块的常用函数. 1. 编译正则 import re p = re.compile(r'ab*') print '[Output]' print type(p) print p p ...
- Linux doxygen的安装与使用
1.安装doxygen 目前最新版本的的doxygen是doxygen1.8.13,安装包可以在官网上下载,网址是:http://www.stack.nl/~dimitri/doxygen/downl ...
- awk遇到windows 的^M
windows在编辑的文档,在linux中显示会在行尾出现一个^M window下编辑的文档:末尾带^M$ linux下编辑的文档:末尾带$ awk中如果存在^M,则会限制print的输出列数(只能输 ...
- poj 1703 Find them, Catch them 【并查集 新写法的思路】
题目地址:http://poj.org/problem?id=1703 Sample Input 1 5 5 A 1 2 D 1 2 A 1 2 D 2 4 A 1 4 Sample Output N ...
- springmvc异常处理(非注解与注解)
1.异常 程序中的异常一般分为两类:预期异常,运行时异常.前者是我们可预知的,我们一般通过捕获和抛出方式处理这些异常.后者主要通过代码规范.测试等手段来减少异常的发生.一般,我们在系统的DAO.Ser ...
- SSH或者SSM开发web,mysql数据库,数据库配置文件配置不当~数据库读写数据乱码问题解决办法。
相信,大家都有遇到过在传入一个中文string,debug自己的每一行代码时,都发现始终是没有乱码的(即:排除了,源码文件的编码格式是没问题的),但是数据进入数据库之后就是乱掉了. 那么很明显问题就出 ...
- 查找文件【TLCL】
locate locate 执行快速的路径名数据库搜索,输出每个与指定子字符串相匹配的路径名. locate bin/zip locate 命令的数据库是updatedb命令创建的. find loc ...
- 安装Tomcat服务器以及错误汇总(tomcat8.0、jdk8)
Tomcat安装和启动 一.下载Tomcat 你可以直接百度Tomcat官网, 或者,直接在地址栏输入他的官网地址:http://tomcat.apache.org/,然后进入他的主页,在主页左侧可以 ...