cocos2d-3.x 创建动画
Posted kingBook
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocos2d-3.x 创建动画相关的知识,希望对你有一定的参考价值。
1.多文件帧序列动画
TrademarkAnimation.h
#ifndef __TRADEMARK_ANIMATION_H__ #define __TRADEMARK_ANIMATION_H__ #include "cocos2d.h" USING_NS_CC; class TrademarkAnimation : public cocos2d::CCLayer{ private: Animate* createAnimate(); public : ~TrademarkAnimation(); virtual bool init(); CREATE_FUNC(TrademarkAnimation); }; #endif
TrademarkAnimation.cpp
#include "TrademarkAnimation.h" bool TrademarkAnimation::init(){ if(!CCLayer::init())return false; Sprite* runSp=Sprite::create(); runSp->setPosition(Point(200,200)); this->addChild(runSp); runSp->runAction(createAnimate()); return true; } Animate* TrademarkAnimation::createAnimate(){ int totalFrames=319; SpriteFrame* frame=NULL; Vector<SpriteFrame*> frameVec; for(int i=1;i<=totalFrames;i++){ //tdmark/tdmark0001.png....tdmark/tdmark0319.png frame=SpriteFrame::create(StringUtils::format("tdmark/tdmark%04d.png",i),Rect(0,0,354,270)); frameVec.pushBack(frame); } Animation* animation=Animation::createWithSpriteFrames(frameVec); animation->setLoops(-1); animation->setDelayPerUnit(0.04f);//: 1/帧频 Animate* action=Animate::create(animation); return action; } TrademarkAnimation::~TrademarkAnimation(){ }
以上是关于cocos2d-3.x 创建动画的主要内容,如果未能解决你的问题,请参考以下文章