2021-12-28 21:00:45 +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 __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
|
|
|
|
|
*/
|
2020-10-17 16:32:16 +08:00
|
|
|
|
class CCS_DLL ActionObject : 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
|
|
|
|
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
|
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
void play(cocos2d::CallFunc* func);
|
|
|
|
|
|
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*/
|
|
|
|
|
void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, cocos2d::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-28 21:00:45 +08:00
|
|
|
|
int valueToInt(const std::string& value);
|
|
|
|
|
bool valueToBool(const std::string& value);
|
|
|
|
|
float valueToFloat(const std::string& value);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
|
cocos2d::Vector<ActionNode*> _actionNodeList;
|
|
|
|
|
std::string _name;
|
|
|
|
|
bool _loop;
|
|
|
|
|
bool _bPause;
|
|
|
|
|
bool _bPlaying;
|
|
|
|
|
float _fUnitTime;
|
|
|
|
|
float _currentTime;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
cocos2d::Scheduler* _pScheduler;
|
|
|
|
|
cocos2d::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
|