fixed cocostudio action can not looping

This commit is contained in:
Liam 2013-11-08 14:34:24 +08:00
parent 56d7da8933
commit 2aaa21255f
9 changed files with 93 additions and 53 deletions

View File

@ -121,7 +121,7 @@ bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
return false;
}
unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mode, unsigned long* size)
unsigned char* FileUtilsWin32::getFileData(const char* filename, const char* mode, long* size)
{
unsigned char * pBuffer = NULL;
CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters.");

View File

@ -58,7 +58,7 @@ protected:
* @return Upon success, a pointer to the data is returned, otherwise NULL.
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
*/
virtual unsigned char* getFileData(const char* filename, const char* mode, unsigned long * size) override;
virtual unsigned char* getFileData(const char* filename, const char* mode, long * size) override;
/**
* Gets full path for filename, resolution directory and search path.

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

@ -142,7 +142,9 @@ 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;
};
}

View File

@ -953,7 +953,7 @@ bool UIRectClippingNode::init()
rect[2] = cocos2d::Point(_clippingSize.width, _clippingSize.height);
rect[3] = cocos2d::Point(0, _clippingSize.height);
cocos2d::Color4F green = {0, 1, 0, 1};
cocos2d::Color4F green = cocos2d::Color4F(0, 1, 0, 1);
_innerStencil->drawPolygon(rect, 4, green, 0, green);
if (cocos2d::ClippingNode::init(_innerStencil))
{
@ -971,7 +971,7 @@ void UIRectClippingNode::setClippingSize(const cocos2d::Size &size)
rect[1] = cocos2d::Point(_clippingSize.width, 0);
rect[2] = cocos2d::Point(_clippingSize.width, _clippingSize.height);
rect[3] = cocos2d::Point(0, _clippingSize.height);
cocos2d::Color4F green = {0, 1, 0, 1};
cocos2d::Color4F green = cocos2d::Color4F(0, 1, 0, 1);
_innerStencil->clear();
_innerStencil->drawPolygon(rect, 4, green, 0, green);
}

View File

@ -12,11 +12,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\CocosGUI.h" />
<ClInclude Include="..\Layout.h" />
<ClInclude Include="..\LayoutParameter.h" />
<ClInclude Include="..\UIButton.h" />
<ClInclude Include="..\UICheckBox.h" />
<ClInclude Include="..\UIDragPanel.h" />
<ClInclude Include="..\UIHelper.h" />
<ClInclude Include="..\UIImageView.h" />
<ClInclude Include="..\UIInputManager.h" />
@ -24,7 +21,9 @@
<ClInclude Include="..\UILabelAtlas.h" />
<ClInclude Include="..\UILabelBMFont.h" />
<ClInclude Include="..\UILayer.h" />
<ClInclude Include="..\UILayout.h" />
<ClInclude Include="..\UILayoutDefine.h" />
<ClInclude Include="..\UILayoutParameter.h" />
<ClInclude Include="..\UIListView.h" />
<ClInclude Include="..\UILoadingBar.h" />
<ClInclude Include="..\UIPageView.h" />
@ -37,11 +36,8 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\CocosGUI.cpp" />
<ClCompile Include="..\Layout.cpp" />
<ClCompile Include="..\LayoutParameter.cpp" />
<ClCompile Include="..\UIButton.cpp" />
<ClCompile Include="..\UICheckBox.cpp" />
<ClCompile Include="..\UIDragPanel.cpp" />
<ClCompile Include="..\UIHelper.cpp" />
<ClCompile Include="..\UIImageView.cpp" />
<ClCompile Include="..\UIInputManager.cpp" />
@ -49,7 +45,9 @@
<ClCompile Include="..\UILabelAtlas.cpp" />
<ClCompile Include="..\UILabelBMFont.cpp" />
<ClCompile Include="..\UILayer.cpp" />
<ClCompile Include="..\UILayout.cpp" />
<ClCompile Include="..\UILayoutDefine.cpp" />
<ClCompile Include="..\UILayoutParameter.cpp" />
<ClCompile Include="..\UIListView.cpp" />
<ClCompile Include="..\UILoadingBar.cpp" />
<ClCompile Include="..\UIPageView.cpp" />

View File

@ -24,9 +24,6 @@
<ClInclude Include="..\UIScrollView.h">
<Filter>UIWidgets\ScrollWidget</Filter>
</ClInclude>
<ClInclude Include="..\UIDragPanel.h">
<Filter>UIWidgets\ScrollWidget</Filter>
</ClInclude>
<ClInclude Include="..\UIListView.h">
<Filter>UIWidgets\ScrollWidget</Filter>
</ClInclude>
@ -72,12 +69,6 @@
<ClInclude Include="..\UILayer.h">
<Filter>System</Filter>
</ClInclude>
<ClInclude Include="..\Layout.h">
<Filter>Layouts</Filter>
</ClInclude>
<ClInclude Include="..\LayoutParameter.h">
<Filter>Layouts</Filter>
</ClInclude>
<ClInclude Include="..\UILayoutDefine.h">
<Filter>Layouts</Filter>
</ClInclude>
@ -87,14 +78,17 @@
<ClInclude Include="..\UIWidget.h">
<Filter>BaseClasses</Filter>
</ClInclude>
<ClInclude Include="..\UILayout.h">
<Filter>Layouts</Filter>
</ClInclude>
<ClInclude Include="..\UILayoutParameter.h">
<Filter>Layouts</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\UIScrollView.cpp">
<Filter>UIWidgets\ScrollWidget</Filter>
</ClCompile>
<ClCompile Include="..\UIDragPanel.cpp">
<Filter>UIWidgets\ScrollWidget</Filter>
</ClCompile>
<ClCompile Include="..\UIListView.cpp">
<Filter>UIWidgets\ScrollWidget</Filter>
</ClCompile>
@ -140,12 +134,6 @@
<ClCompile Include="..\UILayer.cpp">
<Filter>System</Filter>
</ClCompile>
<ClCompile Include="..\Layout.cpp">
<Filter>Layouts</Filter>
</ClCompile>
<ClCompile Include="..\LayoutParameter.cpp">
<Filter>Layouts</Filter>
</ClCompile>
<ClCompile Include="..\UILayoutDefine.cpp">
<Filter>Layouts</Filter>
</ClCompile>
@ -155,5 +143,11 @@
<ClCompile Include="..\UIWidget.cpp">
<Filter>BaseClasses</Filter>
</ClCompile>
<ClCompile Include="..\UILayout.cpp">
<Filter>Layouts</Filter>
</ClCompile>
<ClCompile Include="..\UILayoutParameter.cpp">
<Filter>Layouts</Filter>
</ClCompile>
</ItemGroup>
</Project>