• 大小: 5.44MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-04-10
  • 语言: 其他
  • 标签: cocos2d-x  游戏  源码  

资源简介

一个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\description
     文件          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-rebase.sample
     文件        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个文件信息

评论

共有 条评论