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__
2012-06-19 13:50:11 +08:00
# include "platform/CCPlatformConfig.h"
# include "cocoa/CCObject.h"
# include "cocoa/CCArray.h"
# include "cocoa/CCDictionary.h"
# include "cocoa/CCGeometry.h"
2012-03-16 13:42:53 +08:00
# include "CCSpriteFrame.h"
2011-01-07 09:35:27 +08:00
# include <string>
2010-12-27 10:26:56 +08:00
2012-03-16 13:42:53 +08:00
NS_CC_BEGIN
class CCTexture2D ;
class CCSpriteFrame ;
2012-06-20 18:09:11 +08:00
/**
* @ addtogroup sprite_nodes
* @ {
*/
2012-04-19 14:35:52 +08:00
/** CCAnimationFrame
A frame of the animation . It contains information like :
- sprite frame name
- # of delay units .
- offset
@ since v2 .0
*/
class CC_DLL CCAnimationFrame : public CCObject
{
public :
CCAnimationFrame ( ) ;
virtual ~ CCAnimationFrame ( ) ;
virtual CCObject * copyWithZone ( CCZone * pZone ) ;
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
bool initWithSpriteFrame ( CCSpriteFrame * spriteFrame , float delayUnits , CCDictionary * userInfo ) ;
/** CCSpriteFrameName to be used */
CC_SYNTHESIZE_RETAIN ( CCSpriteFrame * , m_pSpriteFrame , SpriteFrame )
/** how many units of time the frame takes */
CC_SYNTHESIZE ( float , m_fDelayUnits , DelayUnits )
/** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */
CC_SYNTHESIZE_RETAIN ( CCDictionary * , m_pUserInfo , UserInfo )
} ;
2012-03-16 13:42:53 +08:00
/** A CCAnimation object is used to perform animations on the CCSprite objects.
The CCAnimation object contains CCAnimationFrame 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 ] ] ;
*/
class CC_DLL CCAnimation : public CCObject
{
public :
2012-04-19 14:35:52 +08:00
CCAnimation ( ) ;
~ CCAnimation ( void ) ;
2012-03-16 13:42:53 +08:00
public :
2012-04-19 14:35:52 +08:00
/** Creates an animation
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-04-19 14:35:52 +08:00
@ since v0 .99 .5
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCAnimation * animation ( void ) ;
2010-12-27 10:26:56 +08:00
2012-06-14 15:13:16 +08:00
/* Creates an animation with an array of CCSpriteFrame and a delay between frames in seconds.
The frames will be added with one " delay unit " .
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-06-14 15:13:16 +08:00
@ since v0 .99 .5
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCAnimation * animationWithSpriteFrames ( CCArray * arrayOfSpriteFrameNames , float delay = 0.0f ) ;
2012-06-14 15:13:16 +08:00
/* Creates an animation with an array of CCAnimationFrame, the delay per units in seconds and and how many times it should be executed.
2012-06-20 14:31:36 +08:00
@ deprecated : This interface will be deprecated sooner or later .
2012-06-14 15:13:16 +08:00
@ since v2 .0
*/
2012-06-20 11:48:31 +08:00
CC_DEPRECATED_ATTRIBUTE static CCAnimation * animationWithAnimationFrames ( CCArray * arrayOfAnimationFrameNames , float delayPerUnit , unsigned int loops ) ;
2012-06-14 15:13:16 +08:00
/** Creates an animation
2012-04-19 14:35:52 +08:00
@ since v0 .99 .5
*/
2012-06-14 15:13:16 +08:00
static CCAnimation * create ( void ) ;
2012-04-19 14:35:52 +08:00
/* Creates an animation with an array of CCSpriteFrame and a delay between frames in seconds.
The frames will be added with one " delay unit " .
@ since v0 .99 .5
*/
2012-06-14 15:13:16 +08:00
static CCAnimation * createWithSpriteFrames ( CCArray * arrayOfSpriteFrameNames , float delay = 0.0f ) ;
2012-04-19 14:35:52 +08:00
/* Creates an animation with an array of CCAnimationFrame, the delay per units in seconds and and how many times it should be executed.
@ since v2 .0
*/
2012-06-14 15:13:16 +08:00
static CCAnimation * createWithAnimationFrames ( CCArray * arrayOfAnimationFrameNames , float delayPerUnit , unsigned int loops ) ;
2012-04-19 14:35:52 +08:00
/** Adds a CCSpriteFrame to a CCAnimation.
The frame will be added with one " delay unit " .
*/
void addSpriteFrame ( CCSpriteFrame * pFrame ) ;
/** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
The frame will be added with one " delay unit " .
Added to facilitate the migration from v0 .8 to v0 .9 .
*/
void addSpriteFrameWithFileName ( const char * pszFileName ) ;
/** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it.
The frame will be added with one " delay unit " .
Added to facilitate the migration from v0 .8 to v0 .9 .
*/
void addSpriteFrameWithTexture ( CCTexture2D * pobTexture , const CCRect & rect ) ;
bool init ( ) ;
/** Initializes a CCAnimation with frames and a delay between frames
@ since v0 .99 .5
*/
2012-06-14 15:13:16 +08:00
bool initWithSpriteFrames ( CCArray * pFrames , float delay = 0.0f ) ;
2012-04-19 14:35:52 +08:00
/** Initializes a CCAnimation with CCAnimationFrame
@ since v2 .0
*/
bool initWithAnimationFrames ( CCArray * arrayOfAnimationFrames , float delayPerUnit , unsigned int loops ) ;
virtual CCObject * copyWithZone ( CCZone * pZone ) ;
/** total Delay units of the CCAnimation. */
CC_SYNTHESIZE_READONLY ( float , m_fTotalDelayUnits , TotalDelayUnits )
/** Delay in seconds of the "delay unit" */
CC_SYNTHESIZE ( float , m_fDelayPerUnit , DelayPerUnit )
/** duration in seconds of the whole animation. It is the result of totalDelayUnits * delayPerUnit */
CC_PROPERTY_READONLY ( float , m_fDuration , Duration )
/** array of CCAnimationFrames */
CC_SYNTHESIZE_RETAIN ( CCArray * , m_pFrames , Frames )
/** whether or not it shall restore the original frame when the animation finishes */
CC_SYNTHESIZE ( bool , m_bRestoreOriginalFrame , RestoreOriginalFrame )
/** how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ... */
CC_SYNTHESIZE ( unsigned int , m_uLoops , Loops )
2012-03-16 13:42:53 +08:00
} ;
2012-06-20 18:09:11 +08:00
// end of sprite_nodes group
/// @}
2012-03-16 13:42:53 +08:00
NS_CC_END
2010-12-27 10:26:56 +08:00
# endif // __CC_ANIMATION_H__