码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-3.x 创建动画

时间:2016-11-26 17:10:26      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:创建   tde   public   return   cto   private   for   blog   tor   

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 创建动画

标签:创建   tde   public   return   cto   private   for   blog   tor   

原文地址:http://www.cnblogs.com/kingBook/p/6104597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!