#ifndef _h_AnimHelp_h
#define _h_AnimHelp_h
#include "cocos2d.h"
#include "cocos-ext.h"
#include <vector>
using namespace std;
using namespace cocos2d;
using namespace cocos2d::extension;
struct SeqData
{
SeqData():seq_(NULL)
,dt_(0.1f)
{
}
Sequence* seq_;
float dt_;
};
class AnimHelp
{
public:
void callOut(Node* _obj, float dt, SEL_CallFuncND func)
{
if (!_obj)
{
log("[CallOut] obj got nil!");
return;
}
auto _dt = DelayTime::create(dt);
auto _sq = Sequence::create(_dt, func, NULL);
_obj->runAction(_sq);
}
void init(vector<SeqData*> _seq)
{
seq_ = _seq;
index_ = 0;
}
Sequence* getAnim()
{
SeqData* data = seq_[index_];
if (!data)
{
return NULL;
}
return data->seq_;
}
float getTime()
{
SeqData* data = seq_[index_];
if (!data)
{
return NULL;
}
return data->dt_;
}
void setIndex(int _index)
{
index_ = _index;
}
int getIndex()
{
return index_;
}
int getLength()
{
return seq_.size();
}
static AnimHelp* getInstance()
{
if (NULL == instance_)
{
instance_ = new AnimHelp;
}
return instance_;
}
private:
static AnimHelp* instance_;
vector<SeqData* > seq_;
int index_;
};
#define HEARTBEAT(classname, func) void\ ##classname::##func(float dt) \
{ \
auto _index = AnimHelp::getInstance()->getIndex(); \
auto length = AnimHelp::getInstance()->getLength(); \
\
if (length == _index) \
{ \
unschedule(schedule_selector(##classname::##func));\
return; \
} \
\
unschedule(schedule_selector(##classname::##func)); \
schedule(schedule_selector(##classname::##func), AnimHelp::getInstance()->getTime()); \
obj_->runAction(AnimHelp::getInstance()->getAnim()); \
_index++; \
AnimHelp::getInstance()->setIndex(_index); \
}
#endif
播放一个数组中的动画
最新推荐文章于 2022-03-15 19:21:31 发布