为什么我创建了自定义的动作放在sequence里就无法运行
直接用runaction调用没有问题
这样可以运行
pSprite->runAction(CustomRotation);
这样就不行
pSprite->runAction(CCSequence::create(CustomRotation,NULL));
我的自定义类
class CustomAction : public CCActionInterval
{
public:
CCObject* copyWithZone(CCZone* pZone);
~CustomAction();
static CustomAction* create( CCActionInterval* action );
void startWithTarget( CCNode pTarget );
bool initWithAction( CCActionInterval pAction );
void step( float dt );
virtual bool isDone(void);
protected:
void setInnerAction(CCActionInterval* pAction);
CCNode* pInnerTarget;
CCActionInterval* pInnerAction;
};
CustomAction* CustomAction::create( CCActionInterval* pAction )
{
CustomAction* action = new CustomAction();
if (action && action->initWithAction( pAction ) )
{
CCLOG(“create”);
action->autorelease();
return action;
}
CC_SAFE_DELETE(action);
return NULL;
}
bool CustomAction::initWithAction( CCActionInterval* pAction )
{
pAction->retain();
pInnerAction = pAction;
return true;
}
void CustomAction::setInnerAction(CCActionInterval* pAction)
{
if (pInnerAction != pAction)
{
CC_SAFE_RELEASE(pInnerAction);
pInnerAction = pAction;
CC_SAFE_RETAIN(pInnerAction);
}
}
void CustomAction::step(float dt)
{
CCLOG(“Run CustomAction step func”);
CCPoint prePos = pInnerTarget->getPosition();
pInnerAction->step(dt);
CCPoint curPos = pInnerTarget->getPosition();
float tan = -(curPos.y - prePos.y) / (curPos.x - prePos.x);
float degree = atan(tan);
degree = degree / 3.14159f * 180;
pInnerTarget->setRotation(degree + 270);
}
CCObject* CustomAction::copyWithZone(CCZone* pZone)
{
CCZone* pNewZone = NULL;
CustomAction* pCopy = NULL;
if (pZone && pZone->m_pCopyObject)
{
pCopy = (CustomAction*)(pZone->m_pCopyObject);
}
else
{
pCopy = new CustomAction();
pZone = pNewZone = new CCZone(pCopy);
}
CCActionInterval::copyWithZone(pZone);
pCopy->initWithAction(dynamic_cast<CCActionInterval*>(pInnerAction->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
void CustomAction::startWithTarget( CCNode *pTarget )
{
pInnerTarget = pTarget;
CCAction::startWithTarget(pInnerTarget);
pInnerAction->startWithTarget(pInnerTarget);
}
CustomAction::~CustomAction()
{
CC_SAFE_RELEASE(pInnerAction);
}
bool CustomAction::isDone(void)
{
return pInnerAction->isDone();
}