2021-12-26 23:26:34 +08:00
|
|
|
/****************************************************************************
|
2019-11-24 23:15:56 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2013-12-26 16:29:59 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
#ifndef __ActionNODE_H__
|
|
|
|
#define __ActionNODE_H__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCActionFrame.h"
|
|
|
|
#include "DictionaryHelper.h"
|
|
|
|
#include "CocosStudioExport.h"
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
|
2014-06-18 15:55:01 +08:00
|
|
|
class CocoLoader;
|
|
|
|
struct stExpCocoNode;
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL ActionNode : public cocos2d::Ref
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-06-17 13:16:06 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Default constructor
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
ActionNode();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Default destructor
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual ~ActionNode();
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets the time interval of frame.
|
|
|
|
*
|
|
|
|
* @param fTime the time interval of frame
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
void setUnitTime(float fTime);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets the time interval of frame.
|
|
|
|
*
|
|
|
|
* @return fTime the time interval of frame
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
float getUnitTime();
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets tag for ActionNode
|
|
|
|
*
|
|
|
|
* @param tag tag of ActionNode
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
void setActionTag(int tag);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets tag for ActionNode
|
|
|
|
*
|
|
|
|
* @return tag tag of ActionNode
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
int getActionTag();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets node which will run a action.
|
|
|
|
*
|
|
|
|
* @param node which will run a action
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
void setObject(cocos2d::Ref* node);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets node which will run a action.
|
|
|
|
*
|
|
|
|
* @return node which will run a action
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
cocos2d::Ref* getObject();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Insets a ActionFrame to ActionNode.
|
|
|
|
*
|
|
|
|
* @param index the index of ActionFrame
|
|
|
|
*
|
|
|
|
* @param frame the ActionFrame which will be inserted
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
void insertFrame(int index, ActionFrame* frame);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Pushes back a ActionFrame to ActionNode.
|
|
|
|
*
|
|
|
|
* @param frame the ActionFrame which will be added
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
void addFrame(ActionFrame* frame);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Remove a ActionFrame from ActionNode.
|
|
|
|
*
|
|
|
|
* @param frame the ActionFrame which will be removed
|
|
|
|
*/
|
|
|
|
void deleteFrame(ActionFrame* frame);
|
2015-06-17 13:16:06 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Remove all ActionFrames from ActionNode.
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
void clearAllFrame();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets index of first ActionFrame.
|
|
|
|
*
|
|
|
|
* @return index of first ActionFrame
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
int getFirstFrameIndex();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets index of last ActionFrame.
|
|
|
|
*
|
|
|
|
* @return index of last ActionFrame
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
int getLastFrameIndex();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Updates action states to some time.
|
|
|
|
*
|
|
|
|
* @param fTime the time when need to update
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual bool updateActionToTimeLine(float fTime);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Play the action.
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual void playAction();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Stop the action.
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual void stopAction();
|
|
|
|
|
|
|
|
/*init properties with a json dictionary*/
|
|
|
|
virtual void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, Ref* root);
|
2015-06-17 13:16:06 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets if the action is done once time.
|
|
|
|
*
|
|
|
|
* @return that if the action is done once time
|
|
|
|
*/
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual bool isActionDoneOnce();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
protected:
|
2021-12-26 23:26:34 +08:00
|
|
|
int valueToInt(std::string_view value);
|
|
|
|
bool valueToBool(std::string_view value);
|
|
|
|
float valueToFloat(std::string_view value);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
int _currentFrameIndex;
|
|
|
|
int _destFrameIndex;
|
2013-12-26 16:29:59 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
float _fUnitTime;
|
2013-12-26 16:29:59 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
int _actionTag;
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::Spawn* _actionSpawn;
|
2015-06-17 13:16:06 +08:00
|
|
|
cocos2d::Action* _action;
|
|
|
|
cocos2d::Ref* _object;
|
2013-12-26 16:29:59 +08:00
|
|
|
|
2015-06-17 13:16:06 +08:00
|
|
|
std::vector<cocos2d::Vector<ActionFrame*>*> _frameArray;
|
|
|
|
int _frameArrayNum;
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
protected:
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual cocos2d::Node* getActionNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual cocos2d::Spawn* refreshActionProperty();
|
2015-06-17 13:16:06 +08:00
|
|
|
virtual void runAction();
|
|
|
|
virtual void initActionNodeFromRoot(cocos2d::Ref* root);
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void easingToFrame(float duration, float delayTime, ActionFrame* srcFrame, ActionFrame* destFrame);
|
2013-09-20 22:23:13 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
#endif
|