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>的更多相关文章

  1. cocostudio 骨骼动画 setContentScaleFactor

    最近在看骨骼动画,看上去挺容易的,但是照着例子做的时候却出现问题了,骨骼之间出现了很大的缝隙,找了很久才发现原来setContentScaleFactor的原因, 出现间隙,是因为各个骨骼是单独在做缩 ...

  2. cocos2dx骨骼动画Armature源码分析(三)

    代码目录结构 cocos2dx里骨骼动画代码在cocos -> editor-support -> cocostudio文件夹中,win下通过筛选器,文件结构如下.(mac下没有分,是整个 ...

  3. cocos2d-x 3.0 版本 骨骼动画设置shader

    因为骨骼动画是由多个sprite组成, 所以需要遍历每个sprite 才能修改整体, 开头这样设置,在游戏中发现走路状态没问题,攻击状态就有部分sprite没效果 for (auto & ob ...

  4. cocos2dx - v2.3.3编辑器骨骼动画

    接上一节内容:cocos2dx - v2.3.3编辑器简单使用及不同分辨率适配 本节主要Cocos骨骼动画的创建及使用 一.新建 用Cocos Studio工具新建一个状态栏项目.如下图: 当然也可以 ...

  5. cocos2dx加载骨骼动画,获取骨骼位置

    2015/05/13 需求: (1)希望在骨骼上绑定一个粒子特效 (2)获取骨骼的位置 (3)获取骨骼动画的大小 (4)lua 1. cocostudio动画编辑器 (1)绑定粒子特效(跟随骨骼的移动 ...

  6. cocos2dx骨骼动画Armature源码分析(一)

    源码分析一body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-to ...

  7. HTML5骨骼动画Demo | 使用min2d、createjs、pixi播放spine动画

    Spine做骨骼动画是比较流行的,使用起来可能相对复杂,但功能毕竟强大,所以市场占有率较大. 在unity.cocos2d.starling中使用spine已经很成熟了,而HTML5这一块可能刚刚起步 ...

  8. cocos2d-x开发记录:二,基本概念(骨骼动画)

    九,骨骼动画 1.骨骼动画vs Sprite sheets 你能使用sprite sheets 创建动画,它很快又容易.直到你意识到你的游戏需要大量的动画并且内存消耗越来越高,并且需要时间载入全部数据 ...

  9. 初尝2D骨骼动画编辑工具SPINE,并into Unity3D

    一.SPINE使用 研究2D骨骼动画,CYou的朋友介绍我SPINE这个工具,开发自Esoteric Software的一款专门制作2D动画的软件,网络上的资料还很少,我这从半吊子美术技术的角度简单说 ...

随机推荐

  1. Django——Session源码分析

    首先我们导入django.contrib.sessions.middleware这个中间件,查看里面的Session源码 from django.contrib.sessions.middleware ...

  2. jQuery:自学笔记(5)——Ajax

    jQuery:自学笔记(5)——Ajax 使用Ajax快捷函数 说明 出于简化AJAX开发工作的流程,jQuery提供了若干了快捷函数. 实例 1.显示 test.php 返回值(HTML 或 XML ...

  3. 前端 初级篇(CSS)

    CSS 简介 css是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化. 存在方式有三种:元素内联.页面嵌入和外部引入,比较三种方式的优缺点. 语法:styl ...

  4. iOS 关于 Missing iOS Distribution signing identity for.... 等 打包 校验 出现的事故 处理经验

    着实郁闷了一阵子,不知道为什么 证书和配置文件都没有问题 在Archieve后  validate 提示:"Missing iOS Distribution signing identity ...

  5. iOS UIFont 的学习与使用

    通常,我们使用字体 都是系统默认的字体. 有时候 从阅读体验,美观度 设计师都会考虑用一些 更高大尚的字体. 系统字体库 给英文 各种style的发挥空间很大,但是 中文则不然. 但是苹果 给使用中文 ...

  6. freeswitch中集成使用ekho实现TTS功能一

    Linux下安装freeswitch并集成ekho实现TTS 1. linux下安装freeswitch就不多介绍了,具体链接网址: http://www.8000hz.com/archives/14 ...

  7. 【转载】OpenWrt sysupgrade 命令行更新固件到最新版

    OpenWrt sysupgrade 命令行更新固件到最新版 下面我们要使用 sysupgrade 更新固件到trunk最新版. 要注意的是,trunk包含试验的功能,可能不稳定,刷机风险自己承担. ...

  8. Redis之数据存储结构

    今天去中关村软件园面试,被问到:你做项目用到的Redis处理数据用的什么结构?顿时石化,”用到的结构,不就是key-value嘛,还有什么结构?“.面试官说:“平时除了工作,要加强学习,下面的面试我觉 ...

  9. DNS 缓存机制原理

    DNS 缓存机制原理 简单来说,一条域名的DNS记录会在本地有两种缓存:浏览器缓存和操作系统(OS)缓存.在浏览器中访问的时候,会优先访问浏览器缓存, 如果未命中则访问OS缓存,最后再访问DNS服务器 ...

  10. 防止iframe被别的网站引用

    try{ top.location.hostname; if (top.location.hostname != window.location.hostname) { top.location.hr ...