2010-08-05 14:37:36 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
2010-08-05 14:37:36 +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 __ACTION_CCACTION_MANAGER_H__
|
|
|
|
#define __ACTION_CCACTION_MANAGER_H__
|
|
|
|
|
|
|
|
#include "CCAction.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCMutableArray.h"
|
|
|
|
#include "CCObject.h"
|
2010-08-05 14:37:36 +08:00
|
|
|
#include "selector_protocol.h"
|
|
|
|
|
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-09-29 16:33:52 +08:00
|
|
|
struct _hashElement;
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief CCActionManager is a singleton that manages all the actions.
|
2010-08-05 14:37:36 +08:00
|
|
|
Normally you won't need to use this singleton directly. 99% of the cases you will use the CCNode interface,
|
|
|
|
which uses this singleton.
|
|
|
|
But there are some cases where you might need to use this singleton.
|
|
|
|
Examples:
|
|
|
|
- When you want to run an action where the target is different from a CCNode.
|
|
|
|
- When you want to pause / resume the actions
|
|
|
|
|
|
|
|
@since v0.8
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCActionManager : public CCObject, public SelectorProtocol
|
2010-08-05 14:37:36 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCActionManager(void);
|
|
|
|
~CCActionManager(void);
|
2010-09-04 12:02:52 +08:00
|
|
|
bool init(void);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
// actions
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Adds an action with a target.
|
2010-08-05 14:37:36 +08:00
|
|
|
If the target is already present, then the action will be added to the existing target.
|
2010-09-29 17:39:45 +08:00
|
|
|
If the target is not present, a new instance of this target will be created either paused or not, and the action will be added to the newly created target.
|
2010-08-05 14:37:36 +08:00
|
|
|
When the target is paused, the queued actions won't be 'ticked'.
|
|
|
|
*/
|
2010-08-28 12:02:10 +08:00
|
|
|
void addAction(CCAction *pAction, CCNode *pTarget, bool paused);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Removes all actions from all the targets.
|
2010-08-05 14:37:36 +08:00
|
|
|
*/
|
|
|
|
void removeAllActions(void);
|
|
|
|
|
|
|
|
/** Removes all actions from a certain target.
|
|
|
|
All the actions that belongs to the target will be removed.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
void removeAllActionsFromTarget(CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** Removes an action given an action reference.
|
|
|
|
*/
|
|
|
|
void removeAction(CCAction *pAction);
|
|
|
|
|
|
|
|
/** Removes an action given its tag and the target */
|
2011-03-07 17:11:57 +08:00
|
|
|
void removeActionByTag(int tag, CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** Gets an action given its tag an a target
|
|
|
|
@return the Action the with the given tag
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
CCAction* getActionByTag(int tag, CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** Returns the numbers of actions that are running in a certain target.
|
2010-08-05 14:37:36 +08:00
|
|
|
* Composable actions are counted as 1 action. Example:
|
2010-09-29 17:39:45 +08:00
|
|
|
* - If you are running 1 Sequence of 7 actions, it will return 1.
|
|
|
|
* - If you are running 7 Sequences of 2 actions, it will return 7.
|
2010-08-05 14:37:36 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
int numberOfRunningActionsInTarget(CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** Pauses the target: all running actions and newly added actions will be paused.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
void pauseTarget(CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** Resumes the target. All queued actions will be resumed.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
void resumeTarget(CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** Resumes the target. All queued actions will be resumed.
|
|
|
|
@deprecated Use resumeTarget: instead. Will be removed in v1.0.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
void resumeAllActionsForTarget(CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** Pauses the target: all running actions and newly added actions will be paused.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
void pauseAllActionsForTarget(CCObject *pTarget);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
/** purges the shared action manager. It releases the retained instance.
|
|
|
|
* because it uses this, so it can not be static
|
|
|
|
@since v0.99.0
|
|
|
|
*/
|
2010-08-17 14:43:00 +08:00
|
|
|
void purgeSharedManager(void);
|
2010-08-30 15:45:39 +08:00
|
|
|
|
|
|
|
// SelectorProtocol methods
|
|
|
|
|
|
|
|
virtual void selectorProtocolRetain(void);
|
|
|
|
virtual void selectorProtocolRelease(void);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
public:
|
2010-09-28 16:18:05 +08:00
|
|
|
/** returns a shared instance of the CCActionManager */
|
2010-11-16 15:12:09 +08:00
|
|
|
static CCActionManager* sharedManager(void);
|
2010-08-05 14:37:36 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// declared in CCActionManager.m
|
|
|
|
|
2010-09-04 11:48:11 +08:00
|
|
|
void removeActionAtIndex(unsigned int uIndex, struct _hashElement *pElement);
|
|
|
|
void deleteHashElement(struct _hashElement *pElement);
|
|
|
|
void actionAllocWithHashElement(struct _hashElement *pElement);
|
2010-08-05 14:37:36 +08:00
|
|
|
void update(ccTime dt);
|
|
|
|
|
|
|
|
protected:
|
2010-09-04 11:48:11 +08:00
|
|
|
struct _hashElement *m_pTargets;
|
|
|
|
struct _hashElement *m_pCurrentTarget;
|
2010-08-05 14:37:36 +08:00
|
|
|
bool m_bCurrentTargetSalvaged;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __ACTION_CCACTION_MANAGER_H__
|