骨骼动画 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动画的软件,网络上的资料还很少,我这从半吊子美术技术的角度简单说 ...
随机推荐
- 最小化CentOS6.7(64bit)---安装mysql5.5、jdk、tomcat
********mysql******** ------------------------------------------------------------------------------ ...
- 每天一个Linux命令(64)shutdown命令
shutdown以一种安全的方式关闭系统. (1)用法: 用法: shutdown [参数] [时间] (2)功能: 功能: 系统关机命令,shutdown ...
- Windows定时任务没有执行
最近部署网站首页静态化程序,需要定时执行的,由于部署在Windows上,为了方便直接用Windows计划任务做定时了.跑了一段时间发现.首页的静态html文件日期一直是老的,手动执行程序会更新,怀疑任 ...
- Xamarin简介与Xamarin支持MVC设计模式
Create Native iOS, Android,Mac and Windows apps in C#. 官方网站:http://xamarin.com/ 使用武器 Run a C# app, g ...
- c# 类的序列化,以及嵌套问题
简单的序列化,网上很多,但是突然想到一个问题,如果一个类里用到了另一个,那么怎么办,今天试了试,只需要加上序列号标签就可以了 using System.Collections; using Syste ...
- kvm初体验——linux之kvm安装及使用qemu工具安装系统【转】
本文转载自:https://blog.csdn.net/Heimerdinger_Feng/article/details/79119445 一.安装虚拟机之前先升级软件仓库 sudo apt-get ...
- maven deploy 代码
Run As --> Run Configurations ---> Maven Build --->New _Configuration(双击Maven Build可生成) --& ...
- 如何判断Linux服务器是否被入侵?
被入侵服务器的症状 当服务器被没有经验攻击者或者自动攻击程序入侵了的话,他们往往会消耗 100% 的资源.他们可能消耗 CPU 资源来进行数字货币的采矿或者发送垃圾邮件,也可能消耗带宽来发动 DoS ...
- springcloud-Api网关服务Zuul
springcloud项目例子:链接:https://pan.baidu.com/s/1O1PKrdvrq5c8sQUb7dQ5Pg 密码:ynir 1.由来: 如果我的微服务中有很多个独立服务都要对 ...
- 分布式技术 memcached
memcached 是一个高性能的分布式内存对象缓存系统,用于动态web应用,以减轻数据库负载,它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.memcache ...