中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Cocos2d-x動畫工具類

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
1.此工具類的目的是為了方便執(zhí)行動畫,使用TexturePackerGUI工具可以導(dǎo)出plist文件和png圖片,這里我示例圖片叫bxjg.plist和bxjg.png

//////////////////////////////////////.h文件

#ifndef _AnimateUtil_H_
#define _AnimateUtil_H_
#include "cocos2d.h"
using namespace cocos2d;
using namespace std;
class AnimateUtil//動畫工具類
{
public:
//根據(jù)文件名字前綴創(chuàng)建動畫對象                         名稱   播放的間隔    是否循環(huán)播放   
static Animation * createWithSingleFrameName(const char * name, float delay, int Loops);
//根據(jù)文件名字前綴創(chuàng)建動畫對象,指定動畫圖片數(shù)量        名稱    圖片數(shù)量  播放的間隔  是否循環(huán)播放 
static Animation * createWithFrameNameAndNum(const char * name, int num, float delay, int Loops);
};

#endif

/////////////////////////////////.cpp文件

#include "AnimateUtil.h"


Animation * AnimateUtil::createWithSingleFrameName(const char * name, float delay, int Loops)
{
/*將圖片加載到精靈幀緩沖池*/
SpriteFrameCache *frameCache = SpriteFrameCache::getInstance();
Vector<SpriteFrame * > frameVec;
SpriteFrame * frame = NULL;
int index = 1;//小圖片數(shù)量
do 
{
//從SpriteFrame緩沖池獲取SpriteFrame對象
frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", name, index++));
//不斷獲取spriteFrame對象,直到獲取的值為NULL
if (frame == NULL)
{
break;
}
frameVec.pushBack(frame);
} while (true);
//使用SpiteFrame列表創(chuàng)建動畫對象
Animation * animation = Animation::createWithSpriteFrames(frameVec);
animation->setLoops(Loops);//設(shè)置是否循環(huán)
animation->setRestoreOriginalFrame(true);
animation->setDelayPerUnit(delay);//設(shè)置動畫間隙
return animation;
}


Animation * AnimateUtil::createWithFrameNameAndNum(const char * name, int num, float delay, int Loops)
{
SpriteFrameCache * frameCache = SpriteFrameCache::getInstance();


SpriteFrame * frame = NULL;
Vector<SpriteFrame *> frameVec;
int index = 1;
for (int  i = 1; i <= num; i++)
{
frame = frameCache->getSpriteFrameByName(StringUtils::format("%s%d.png", name, index++));
if (frame ==NULL)
{
break;
}
frameVec.pushBack(frame);
}
Animation * animation = Animation::createWithSpriteFrames(frameVec);
animation->setLoops(Loops);
animation->setRestoreOriginalFrame(true);
animation->setDelayPerUnit(delay);
return animation;
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:開放一個繼承于FragmentActivity的頁面

下一篇:利用PHPEXCEL導(dǎo)出excel文件