2021-12-31 12:12:40 +08:00
|
|
|
/****************************************************************************
|
2019-11-24 23:15:56 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2019-11-23 20:27:39 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ActionNODE_H__
|
|
|
|
#define __ActionNODE_H__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCActionFrame.h"
|
|
|
|
#include "DictionaryHelper.h"
|
|
|
|
#include "CocosStudioExport.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
class CocoLoader;
|
|
|
|
struct stExpCocoNode;
|
|
|
|
/**
|
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
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Default constructor
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
ActionNode();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Default destructor
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getUnitTime();
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets tag for ActionNode
|
|
|
|
*
|
|
|
|
* @param tag tag of ActionNode
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setActionTag(int tag);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets tag for ActionNode
|
|
|
|
*
|
|
|
|
* @return tag tag of ActionNode
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +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);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Remove all ActionFrames from ActionNode.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void clearAllFrame();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets index of first ActionFrame.
|
|
|
|
*
|
|
|
|
* @return index of first ActionFrame
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
int getFirstFrameIndex();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets index of last ActionFrame.
|
|
|
|
*
|
|
|
|
* @return index of last ActionFrame
|
|
|
|
*/
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool updateActionToTimeLine(float fTime);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Play the action.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void playAction();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Stop the action.
|
|
|
|
*/
|
2019-11-23 20:27:39 +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);
|
2019-11-23 20:27:39 +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
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual bool isActionDoneOnce();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2021-12-31 12:12:40 +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
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
int _currentFrameIndex;
|
|
|
|
int _destFrameIndex;
|
|
|
|
|
|
|
|
float _fUnitTime;
|
|
|
|
|
|
|
|
int _actionTag;
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::Spawn* _actionSpawn;
|
2019-11-23 20:27:39 +08:00
|
|
|
cocos2d::Action* _action;
|
|
|
|
cocos2d::Ref* _object;
|
|
|
|
|
|
|
|
std::vector<cocos2d::Vector<ActionFrame*>*> _frameArray;
|
|
|
|
int _frameArrayNum;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual cocos2d::Node* getActionNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual cocos2d::Spawn* refreshActionProperty();
|
2019-11-23 20:27:39 +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);
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|