資源簡(jiǎn)介
一個(gè)cocos2d-x的闖關(guān)類游戲。我也是下的比人的,不過(guò)在2.1.0的版本下調(diào)通了,僅供學(xué)習(xí)
代碼片段和文件信息
#include?“AnimationManager.h“
DECLARE_SINGLETON_MEMBER(AnimationManager);
AnimationManager::AnimationManager()
{
}
AnimationManager::~AnimationManager()
{
//CCDirector會(huì)自己清除AnimationCache
//CCAnimationCache::purgeSharedAnimationCache();
}
bool?AnimationManager::initAnimationMap()
{
char?temp[20];
sprintf(temp?“%d“?aDown);
//加載勇士向下走的動(dòng)畫
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kDown)?temp);
sprintf(temp?“%d“?aRight);
//加載勇士向右走的動(dòng)畫
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kRight)?temp);
sprintf(temp?“%d“?aLeft);
//加載勇士向左走的動(dòng)畫
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kLeft)?temp);
sprintf(temp?“%d“?aUp);
//加載勇士向上走的動(dòng)畫
CCAnimationCache::sharedAnimationCache()->addAnimation(createHeroMovingAnimationByDirection(kUp)?temp);
//加載戰(zhàn)斗動(dòng)畫
sprintf(temp?“%d“?aFight);
CCAnimationCache::sharedAnimationCache()->addAnimation(createFightAnimation()?temp);
//加載NPC動(dòng)畫
CCAnimationCache::sharedAnimationCache()->addAnimation(createNPCAnimation()?“npc0“);
return?true;
}
CCAnimation*?AnimationManager::createHeroMovingAnimationByDirection(HeroDirection?direction)
{
CCTexture2D?*heroTexture?=?CCTextureCache::sharedTextureCache()->addImage(“hero.png“);
CCSpriteframe?*frame0?*frame1?*frame2?*frame3;
//第二個(gè)參數(shù)表示顯示區(qū)域的x?y?width?height,根據(jù)direction來(lái)確定顯示的y坐標(biāo)
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表示每幀動(dòng)畫間的間隔
animation->initWithSpriteframes(animframes?0.05f);
animframes->release();
return?animation;
}
//創(chuàng)建戰(zhàn)斗動(dòng)畫模板
CCAnimation*?AnimationManager::createFightAnimation()
{
//定義每幀的序號(hào)
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++)?
{
//計(jì)算每幀在整個(gè)紋理中的偏移量
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*
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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個(gè)文件信息
評(píng)論
共有 條評(píng)論