标签:
http://blog.csdn.net/zh13544539220/article/details/45223863
上篇文章是关于Action的工作流程和ActionManager的执行原理,本文说说Action的分类和具体的设计
动作类型的分类:
一、限时动作:FiniteTimeActionvoid CallFunc::execute() {
if (_callFunc) {
(_selectorTarget->*_callFunc)();
} else if( _function ){
_function();
}
}void CallFuncN::execute() {
if (_callFuncN) {
(_selectorTarget->*_callFuncN)(_target);
}
else if (_functionN) {
_functionN(_target);
}
} void __CCCallFuncND::execute()
{
if (_callFuncND)
{
(_selectorTarget->*_callFuncND)(_target, _data);
}
}void __CCCallFuncO::execute()
{
if (_callFuncO) {
(_selectorTarget->*_callFuncO)(_object);
}
}void RemoveSelf::update(float time) {
CC_UNUSED_PARAM(time);
_target->removeFromParentAndCleanup(_isNeedCleanUp);
}MoveBy* MoveBy::reverse() const
{
return MoveBy::create(_duration, Vec2( -_positionDelta.x, -_positionDelta.y));
}void MoveTo::startWithTarget(Node *target)
{
MoveBy::startWithTarget(target);
_positionDelta = _endPosition - target->getPosition();
} Speed* Speed::create(ActionInterval* action, float speed)
{
Speed *ret = new (std::nothrow) Speed();
if (ret && ret->initWithAction(action, speed))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
void Speed::step(float dt)
{
_innerAction->step(dt * _speed);
}void EaseIn::update(float time)
{
_inner->update(tweenfunc::easeIn(time, _rate));
}Spawn* Spawn::create(const Vector<FiniteTimeAction*>& arrayOfActions)
{
Spawn* ret = nullptr;
do
{
auto count = arrayOfActions.size();
CC_BREAK_IF(count == 0);
auto prev = arrayOfActions.at(0);
if (count > 1)
{
for (int i = 1; i < arrayOfActions.size(); ++i)
{
prev = createWithTwoActions(prev, arrayOfActions.at(i));
}
}
else
{
// If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action.
prev = createWithTwoActions(prev, ExtraAction::create());
}
ret = static_cast<Spawn*>(prev);
}while (0);
return ret;
}标签:
原文地址:http://blog.csdn.net/zh13544539220/article/details/45315113