2010-12-27 10:26:56 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-01 16:11:31 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2010-12-27 10:26:56 +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 __CC_ANIMATION_H__
|
|
|
|
#define __CC_ANIMATION_H__
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCPlatformConfig.h"
|
|
|
|
#include "CCObject.h"
|
|
|
|
#include "CCMutableArray.h"
|
|
|
|
#include "CCGeometry.h"
|
2011-01-07 09:35:27 +08:00
|
|
|
#include <string>
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
namespace cocos2d {
|
|
|
|
class CCSpriteFrame;
|
|
|
|
class CCTexture2D;
|
|
|
|
/** A CCAnimation object is used to perform animations on the CCSprite objects.
|
|
|
|
|
|
|
|
The CCAnimation object contains CCSpriteFrame objects, and a possible delay between the frames.
|
|
|
|
You can animate a CCAnimation object by using the CCAnimate action. Example:
|
|
|
|
|
|
|
|
[sprite runAction:[CCAnimate actionWithAnimation:animation]];
|
|
|
|
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCAnimation : public CCObject
|
2011-01-07 09:35:27 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::string m_nameStr;
|
|
|
|
float m_fDelay;
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCSpriteFrame*> *m_pobFrames;
|
2011-01-07 09:35:27 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
// attributes
|
|
|
|
|
|
|
|
/** get name of the animation */
|
|
|
|
inline const char* getName(void) { return m_nameStr.c_str(); }
|
|
|
|
/** set name of the animation */
|
|
|
|
inline void setName(const char *pszName){ m_nameStr = pszName; }
|
|
|
|
|
|
|
|
/** get delay between frames in seconds */
|
|
|
|
inline float getDelay(void) { return m_fDelay; }
|
|
|
|
/** set delay between frames in seconds */
|
|
|
|
inline void setDelay(float fDelay) { m_fDelay = fDelay; }
|
|
|
|
|
|
|
|
/** get array of frames */
|
2011-03-07 17:11:57 +08:00
|
|
|
inline CCMutableArray<CCSpriteFrame*>* getFrames(void) { return m_pobFrames; }
|
2011-01-07 09:35:27 +08:00
|
|
|
/** set array of frames, the Frames is retained */
|
2011-03-07 17:11:57 +08:00
|
|
|
inline void setFrames(CCMutableArray<CCSpriteFrame*> *pFrames)
|
2011-01-07 09:35:27 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RETAIN(pFrames);
|
|
|
|
CC_SAFE_RELEASE(m_pobFrames);
|
2011-01-07 09:35:27 +08:00
|
|
|
m_pobFrames = pFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
~CCAnimation(void);
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Initializes a CCAnimation with frames.
|
|
|
|
@since v0.99.5
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
2011-03-18 14:31:29 +08:00
|
|
|
bool initWithFrames(CCMutableArray<CCSpriteFrame*> *pFrames);
|
2011-01-07 09:35:27 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Initializes a CCAnimation with frames and a delay between frames
|
|
|
|
@since v0.99.5
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
2011-03-18 14:31:29 +08:00
|
|
|
bool initWithFrames(CCMutableArray<CCSpriteFrame*> *pFrames, float delay);
|
2011-01-07 09:35:27 +08:00
|
|
|
|
|
|
|
/** adds a frame to a CCAnimation */
|
|
|
|
void addFrame(CCSpriteFrame *pFrame);
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
|
|
|
|
Added to facilitate the migration from v0.8 to v0.9.
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
|
|
|
void addFrameWithFileName(const char *pszFileName);
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it.
|
|
|
|
Added to facilitate the migration from v0.8 to v0.9.
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
2011-08-17 21:19:57 +08:00
|
|
|
void addFrameWithTexture(CCTexture2D* pobTexture, const CCRect& rect);
|
2011-01-07 09:35:27 +08:00
|
|
|
|
|
|
|
bool init(void);
|
|
|
|
|
|
|
|
public:
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Creates an animation
|
|
|
|
@since v0.99.5
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
|
|
|
static CCAnimation* animation(void);
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/** Creates an animation with frames.
|
|
|
|
@since v0.99.5
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
2011-03-18 14:31:29 +08:00
|
|
|
static CCAnimation* animationWithFrames(CCMutableArray<CCSpriteFrame*> *frames);
|
2011-01-07 09:35:27 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
/* Creates an animation with frames and a delay between frames.
|
|
|
|
@since v0.99.5
|
2011-01-07 09:35:27 +08:00
|
|
|
*/
|
2011-03-18 14:31:29 +08:00
|
|
|
static CCAnimation* animationWithFrames(CCMutableArray<CCSpriteFrame*> *frames, float delay);
|
2010-12-27 10:26:56 +08:00
|
|
|
};
|
|
|
|
} // end of name sapce cocos2d
|
|
|
|
|
|
|
|
#endif // __CC_ANIMATION_H__
|