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
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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 __ActionObject_H__
|
|
|
|
#define __ActionObject_H__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCActionNode.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "2d/CCActionInstant.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#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
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
class CCS_DLL ActionObject : public ax::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
|
|
|
ActionObject();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Default destructor
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~ActionObject();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets name for object
|
|
|
|
*
|
|
|
|
* @param name name of object
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setName(const char* name);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets name of object
|
|
|
|
*
|
|
|
|
* @return name of object
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
const char* getName();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets if the action will loop play.
|
|
|
|
*
|
|
|
|
* @param bLoop that if the action will loop play
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setLoop(bool bLoop);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets if the action will loop play.
|
|
|
|
*
|
|
|
|
* @return that if the action will loop play
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool getLoop();
|
|
|
|
|
|
|
|
/**
|
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 the time interval of frame
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getUnitTime();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Sets the current time of frame.
|
|
|
|
*
|
|
|
|
* @param fTime the current time of frame
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setCurrentTime(float fTime);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets the current time of frame.
|
|
|
|
*
|
|
|
|
* @return the current time of frame
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getCurrentTime();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Gets the total time of frame.
|
|
|
|
*
|
|
|
|
* @return the total time of frame
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getTotalTime();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Return if the action is playing.
|
|
|
|
*
|
|
|
|
* @return true if the action is playing, false the otherwise
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
bool isPlaying();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Play the action.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void play();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Play the action.
|
|
|
|
*
|
|
|
|
* @param func Action Call Back
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void play(ax::CallFunc* func);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
|
|
|
* Pause the action.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void pause();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Stop the action.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void stop();
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Adds a ActionNode to play the action.
|
|
|
|
*
|
|
|
|
* @param node the ActionNode which will play the action
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void addActionNode(ActionNode* node);
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Removes a ActionNode which play the action.
|
|
|
|
*
|
|
|
|
* @param node the ActionNode which play the action
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void removeActionNode(ActionNode* node);
|
|
|
|
|
|
|
|
/*update frame method*/
|
|
|
|
void updateToFrameByTime(float fTime);
|
|
|
|
|
|
|
|
/*init properties with a json dictionary*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void initWithDictionary(const rapidjson::Value& dic, ax::Ref* root);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, ax::Ref* root);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/*scheduler update function*/
|
|
|
|
void simulationActionUpdate(float dt);
|
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
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vector<ActionNode*> _actionNodeList;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string _name;
|
|
|
|
bool _loop;
|
|
|
|
bool _bPause;
|
|
|
|
bool _bPlaying;
|
|
|
|
float _fUnitTime;
|
|
|
|
float _currentTime;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Scheduler* _pScheduler;
|
|
|
|
ax::CallFunc* _CallBack;
|
2019-11-23 20:27:39 +08:00
|
|
|
float _fTotalTime;
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|