Merge pull request #4215 from liamcindy/develop

[ci skip]fixed ui animation play error
This commit is contained in:
minggo 2013-11-13 17:47:39 -08:00
commit 408ab94eba
4 changed files with 73 additions and 25 deletions

View File

@ -33,16 +33,16 @@ using namespace gui;
namespace cocostudio {
ActionNode::ActionNode()
: _currentFrameIndex(0)
, _destFrameIndex(0)
, _fUnitTime(0.1f)
, _actionTag(0)
, _actionSpawn(NULL)
, _action(NULL)
, _object(NULL)
, _frameArray(NULL)
, _frameArrayNum(0)
ActionNode::ActionNode()
: _currentFrameIndex(0)
, _destFrameIndex(0)
, _fUnitTime(0.1f)
, _actionTag(0)
, _actionSpawn(NULL)
, _action(NULL)
, _object(NULL)
, _frameArray(NULL)
, _frameArrayNum(0)
{
_frameArray = Array::create();
_frameArray->retain();
@ -322,7 +322,7 @@ Spawn * ActionNode::refreshActionProperty()
return _actionSpawn;
}
void ActionNode::playAction(bool bloop)
void ActionNode::playAction()
{
if ( _object == NULL || _actionSpawn == NULL)
{
@ -333,14 +333,8 @@ void ActionNode::playAction(bool bloop)
{
_action->release();
}
if (bloop)
{
_action = RepeatForever::create(_actionSpawn);
}
else
{
_action = Sequence::create(_actionSpawn, NULL);
}
_action = Sequence::create(_actionSpawn, NULL);
_action->retain();
this->runAction();
@ -480,4 +474,14 @@ void ActionNode::easingToFrame(float duration,float delayTime,ActionFrame* destF
cAction->update(delayTime);
}
bool ActionNode::isActionDoneOnce()
{
if (_action == nullptr)
{
return true;
}
return _action->isDone();
}
}

View File

@ -136,10 +136,8 @@ public:
/**
* Play the action.
*
* @param bloop true the
*/
virtual void playAction(bool bloop);
virtual void playAction();
/**
* Stop the action.
@ -148,6 +146,13 @@ public:
/*init properties with a json dictionary*/
virtual void initWithDictionary(JsonDictionary* dic,cocos2d::Object* root);
/**
* Gets if the action is done once time.
*
* @return that if the action is done once time
*/
virtual bool isActionDoneOnce();
protected:
int _currentFrameIndex;
int _destFrameIndex;

View File

@ -25,7 +25,7 @@
#include "cocostudio/CCActionObject.h"
#include "cocostudio/DictionaryHelper.h"
using namespace cocos2d;
using namespace cocos2d;
namespace cocostudio {
@ -37,15 +37,19 @@ ActionObject::ActionObject()
, _bPlaying(false)
, _fUnitTime(0.1f)
, _currentTime(0.0f)
, _pScheduler(NULL)
{
_actionNodeList = Array::create();
_actionNodeList->retain();
_pScheduler = new Scheduler();
Director::sharedDirector()->getScheduler()->scheduleUpdateForTarget(_pScheduler, 0, false);
}
ActionObject::~ActionObject()
{
_actionNodeList->removeAllObjects();
_actionNodeList->release();
CC_SAFE_DELETE(_pScheduler);
}
void ActionObject::setName(const char* name)
@ -134,11 +138,16 @@ void ActionObject::removeActionNode(ActionNode* node)
void ActionObject::play()
{
stop();
this->updateToFrameByTime(0.0f);
int frameNum = _actionNodeList->count();
for ( int i = 0; i < frameNum; i++ )
{
ActionNode* actionNode = (ActionNode*)_actionNodeList->getObjectAtIndex(i);
actionNode->playAction( getLoop());
actionNode->playAction();
}
if (_loop)
{
_pScheduler->scheduleSelector(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f , kRepeatForever, 0.0f, false);
}
}
@ -157,6 +166,7 @@ void ActionObject::stop()
actionNode->stopAction();
}
_pScheduler->unscheduleSelector(schedule_selector(ActionObject::simulationActionUpdate), this);
_bPause = false;
}
@ -174,4 +184,30 @@ void ActionObject::updateToFrameByTime(float fTime)
}
}
void ActionObject::simulationActionUpdate(float dt)
{
if (_loop)
{
bool isEnd = true;
int nodeNum = _actionNodeList->count();
for ( int i = 0; i < nodeNum; i++ )
{
ActionNode* actionNode = (ActionNode*)_actionNodeList->objectAtIndex(i);
if (actionNode->isActionDoneOnce() == false)
{
isEnd = false;
break;
}
}
if (isEnd)
{
this->play();
}
CCLOG("ActionObject Update");
}
}
}

View File

@ -143,6 +143,8 @@ public:
/*init properties with a json dictionary*/
void initWithDictionary(JsonDictionary* dic,cocos2d::Object* root);
/*scheduler update function*/
void simulationActionUpdate(float dt);
protected:
cocos2d::Array* _actionNodeList;/*actionnode*/
std::string _name;
@ -151,6 +153,7 @@ protected:
bool _bPlaying;
float _fUnitTime;
float _currentTime;
cocos2d::Scheduler *_pScheduler;
};
}