资源简介
一个cocos2d-x的闯关类游戏。我也是下的比人的,不过在2.1.0的版本下调通了,仅供学习

代码片段和文件信息
#include “AnimationManager.h“
DECLARE_SINGLETON_MEMBER(AnimationManager);
AnimationManager::AnimationManager()
{
}
AnimationManager::~AnimationManager()
{
//CCDirector会自己清除AnimationCache
//CCAnimationCache::purgeSharedAnimationCache();
}
bool AnimationManager::initAnimationMap()
{
char temp[20];
sprintf(temp “%d“ aDown);
//加载勇士向下走的动画
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kDown) temp);
sprintf(temp “%d“ aRight);
//加载勇士向右走的动画
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kRight) temp);
sprintf(temp “%d“ aLeft);
//加载勇士向左走的动画
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kLeft) temp);
sprintf(temp “%d“ aUp);
//加载勇士向上走的动画
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kUp) temp);
//加载战斗动画
sprintf(temp “%d“ aFight);
CCAnimationCache::sharedAnimationCache()->addAnimation(createFightAnimation() temp);
//加载NPC动画
CCAnimationCache::sharedAnimationCache()->addAnimation(createNPCAnimation() “npc0“);
return true;
}
CCAnimation* AnimationManager::createHeroMovingAnimationByDirection(HeroDirection direction)
{
CCTexture2D *heroTexture = CCTextureCache::sharedTextureCache()->addImage(“hero.png“);
CCSpriteframe *frame0 *frame1 *frame2 *frame3;
//第二个参数表示显示区域的x y width height,根据direction来确定显示的y坐标
frame0 = CCSpriteframe::createWithTexture(heroTexture cocos2d::CCRectMake(32*0 32*direction 32 32));
frame1 = CCSpriteframe::createWithTexture(heroTexture cocos2d::CCRectMake(32*1 32*direction 32 32));
frame2 = CCSpriteframe::createWithTexture(heroTexture cocos2d::CCRectMake(32*2 32*direction 32 32));
frame3 = CCSpriteframe::createWithTexture(heroTexture cocos2d::CCRectMake(32*3 32*direction 32 32));
CCArray * animframes = new CCArray(4);
animframes->addobject(frame0);
animframes->addobject(frame1);
animframes->addobject(frame2);
animframes->addobject(frame3);
CCAnimation* animation = new CCAnimation();
//0.05f表示每帧动画间的间隔
animation->initWithSpriteframes(animframes 0.05f);
animframes->release();
return animation;
}
//创建战斗动画模板
CCAnimation* AnimationManager::createFightAnimation()
{
//定义每帧的序号
int fightAnim[] =
{
46810131517192022
};
CCArray* animframes = new CCArray();
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(“sword.png“);
CCSpriteframe *frame;
int x y;
for (int i = 0; i < 10; i++)
{
//计算每帧在整个纹理中的偏移量
x = fightAnim[i] % 5 - 1;
y = fightAnim[i] / 5;
frame = CCSpriteframe::createWithTexture(texture cocos2d::CCRectMake(192*x 192*y 192 192));
//第17和19帧在y方向上有-8的偏移
if (fightAnim[i] == 17 || fightAnim[i] == 19)
{
frame->setOffsetInPixels( ccp(0 -8) );
}
animframes->addobject(frame);
}
CCAnimation* animation = new CCAnimation();
animation->initWithSpriteframes(animframes 0.1f);
animframes->release();
return animation;
}
CCAnimation*
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-02-24 09:39 MTGame\
文件 6148 2013-03-05 09:32 MTGame\.DS_Store
目录 0 2013-03-05 09:40 __MACOSX\
目录 0 2013-03-05 09:40 __MACOSX\MTGame\
文件 82 2013-03-05 09:32 __MACOSX\MTGame\._.DS_Store
目录 0 2013-03-05 09:36 MTGame\.git\
目录 0 2013-02-24 09:38 MTGame\.git\branches\
文件 15 2013-02-24 09:38 MTGame\.git\COMMIT_EDITMSG
文件 138 2013-02-24 09:38 MTGame\.git\config
文件 73 2013-02-24 09:38 MTGame\.git\desc
文件 23 2013-02-24 09:38 MTGame\.git\HEAD
目录 0 2013-02-24 09:38 MTGame\.git\hooks\
文件 452 2013-02-24 09:38 MTGame\.git\hooks\applypatch-msg.sample
文件 896 2013-02-24 09:38 MTGame\.git\hooks\commit-msg.sample
文件 189 2013-02-24 09:38 MTGame\.git\hooks\post-update.sample
文件 398 2013-02-24 09:38 MTGame\.git\hooks\pre-applypatch.sample
文件 1704 2013-02-24 09:38 MTGame\.git\hooks\pre-commit.sample
文件 4951 2013-02-24 09:38 MTGame\.git\hooks\pre-reba
文件 1239 2013-02-24 09:38 MTGame\.git\hooks\prepare-commit-msg.sample
文件 3611 2013-02-24 09:38 MTGame\.git\hooks\update.sample
文件 56408 2013-02-24 10:06 MTGame\.git\index
目录 0 2013-02-24 09:38 MTGame\.git\info\
文件 35 2013-02-24 09:38 MTGame\.git\info\exclude
目录 0 2013-03-05 09:40 __MACOSX\MTGame\.git\
目录 0 2013-03-05 09:40 __MACOSX\MTGame\.git\info\
文件 171 2013-02-24 09:38 __MACOSX\MTGame\.git\info\._exclude
目录 0 2013-02-24 09:38 MTGame\.git\logs\
文件 160 2013-02-24 09:38 MTGame\.git\logs\HEAD
目录 0 2013-02-24 09:38 MTGame\.git\logs\refs\
目录 0 2013-02-24 09:38 MTGame\.git\logs\refs\heads\
文件 160 2013-02-24 09:38 MTGame\.git\logs\refs\heads\master
............此处省略1811个文件信息
相关资源
-
fli
nk核心源码(追源索骥:透过源码 - Scratch源码
- E4A无障碍跨程序操作类库(带源码、
- 设备管理系统源码
- 安卓wifi直连app源码
- flash3.0小游戏
- Scrach 欢乐狙击手.sb2
- 我的世界源码(易语言版)
- labview编程软件滤波器以及编写程序设
- 我的界面(visual foxpro)源码
- 易语言:一键cf基址源码
- The Secret Path 3D 3D魔方迷宫[源码][scra
- scratch垃圾分类源码(最终版本).sb
- 安卓QQ6.71协议源码易语言,qq协议源码
- 编译原理实验工具及参考源码(lex&
- E盾偷后台工具源码
- UNIX/LINUX编程实践教程的源码
- 十以内加减法练习 powerbuilder源码
- linux应用层的华容道游戏源代码
- 农场开发项目
- OCR源码
- PLC上位机编程软件
- 用foobar2000听google音乐[更新一下]
- 学生信息管理系统源码
- 用VC 编写的仿QQ聊天室程序源代码
- 毕业论文之温度传感器DS18B20(源码
- 可自定义导航网站源码
- 栅栏填充算法源码(VC)
- msp430F149操作红外接收模块源码
- [免费]图像识别c 源码
评论
共有 条评论