2010-12-27 10:26:56 +08:00
/****************************************************************************
2012-09-24 21:22:20 +08:00
Copyright ( c ) 2010 - 2012 cocos2d - x . org
2011-03-19 10:59:01 +08:00
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
2013-06-20 14:13:12 +08:00
class Texture2D ;
class SpriteFrame ;
2012-03-16 13:42:53 +08:00
2012-06-20 18:09:11 +08:00
/**
* @ addtogroup sprite_nodes
* @ {
*/
2013-06-20 14:13:12 +08:00
/** AnimationFrame
2012-04-19 14:35:52 +08:00
A frame of the animation . It contains information like :
- sprite frame name
- # of delay units .
- offset
@ since v2 .0
*/
2013-06-20 14:13:12 +08:00
class CC_DLL AnimationFrame : public Object , public Clonable
2012-04-19 14:35:52 +08:00
{
public :
2013-06-20 14:13:12 +08:00
AnimationFrame ( ) ;
virtual ~ AnimationFrame ( ) ;
2013-07-08 23:05:47 +08:00
2012-04-19 14:35:52 +08:00
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
2013-06-20 14:13:12 +08:00
bool initWithSpriteFrame ( SpriteFrame * spriteFrame , float delayUnits , Dictionary * userInfo ) ;
2013-06-19 06:06:53 +08:00
2013-06-20 14:13:12 +08:00
/** returns a copy of the AnimationFrame */
virtual AnimationFrame * clone ( ) const ;
2013-06-19 06:06:53 +08:00
2013-06-20 14:13:12 +08:00
/** SpriteFrameName to be used */
CC_SYNTHESIZE_RETAIN ( SpriteFrame * , _spriteFrame , SpriteFrame )
2012-04-19 14:35:52 +08:00
/** how many units of time the frame takes */
2013-06-15 14:03:30 +08:00
CC_SYNTHESIZE ( float , _delayUnits , DelayUnits )
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/** A AnimationFrameDisplayedNotification notification will be broadcast when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcast. */
CC_SYNTHESIZE_RETAIN ( Dictionary * , _userInfo , UserInfo )
2012-04-19 14:35:52 +08:00
} ;
2012-03-16 13:42:53 +08:00
2013-06-20 14:13:12 +08:00
/** A Animation object is used to perform animations on the Sprite objects.
2012-03-16 13:42:53 +08:00
2013-06-20 14:13:12 +08:00
The Animation object contains AnimationFrame objects , and a possible delay between the frames .
You can animate a Animation object by using the Animate action . Example :
2012-03-16 13:42:53 +08:00
2013-06-20 14:13:12 +08:00
[ sprite runAction : [ Animate actionWithAnimation : animation ] ] ;
2012-03-16 13:42:53 +08:00
*/
2013-06-20 14:13:12 +08:00
class CC_DLL Animation : public Object , public Clonable
2012-03-16 13:42:53 +08:00
{
public :
2013-06-20 14:13:12 +08:00
Animation ( ) ;
~ Animation ( void ) ;
2012-03-16 13:42:53 +08:00
public :
2012-04-19 14:35:52 +08:00
/** Creates an animation
@ since v0 .99 .5
*/
2013-06-20 14:13:12 +08:00
static Animation * create ( void ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/* Creates an animation with an array of SpriteFrame and a delay between frames in seconds.
2012-04-19 14:35:52 +08:00
The frames will be added with one " delay unit " .
@ since v0 .99 .5
*/
2013-06-20 14:13:12 +08:00
static Animation * createWithSpriteFrames ( Array * arrayOfSpriteFrameNames , float delay = 0.0f ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/* Creates an animation with an array of AnimationFrame, the delay per units in seconds and and how many times it should be executed.
2012-04-19 14:35:52 +08:00
@ since v2 .0
*/
2013-06-20 14:13:12 +08:00
static Animation * create ( Array * arrayOfAnimationFrameNames , float delayPerUnit , unsigned int loops ) ;
static Animation * create ( Array * arrayOfAnimationFrameNames , float delayPerUnit ) {
return Animation : : create ( arrayOfAnimationFrameNames , delayPerUnit , 1 ) ;
2012-08-04 05:33:41 +08:00
}
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/** Adds a SpriteFrame to a Animation.
2012-04-19 14:35:52 +08:00
The frame will be added with one " delay unit " .
*/
2013-06-20 14:13:12 +08:00
void addSpriteFrame ( SpriteFrame * pFrame ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/** Adds a frame with an image filename. Internally it will create a SpriteFrame and it will add it.
2012-04-19 14:35:52 +08:00
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 ) ;
2013-06-20 14:13:12 +08:00
/** Adds a frame with a texture and a rect. Internally it will create a SpriteFrame and it will add it.
2012-04-19 14:35:52 +08:00
The frame will be added with one " delay unit " .
Added to facilitate the migration from v0 .8 to v0 .9 .
*/
2013-06-20 14:13:12 +08:00
void addSpriteFrameWithTexture ( Texture2D * pobTexture , const Rect & rect ) ;
2012-04-19 14:35:52 +08:00
bool init ( ) ;
2013-06-20 14:13:12 +08:00
/** Initializes a Animation with frames and a delay between frames
2012-04-19 14:35:52 +08:00
@ since v0 .99 .5
*/
2013-06-20 14:13:12 +08:00
bool initWithSpriteFrames ( Array * pFrames , float delay = 0.0f ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/** Initializes a Animation with AnimationFrame
2012-04-19 14:35:52 +08:00
@ since v2 .0
*/
2013-06-20 14:13:12 +08:00
bool initWithAnimationFrames ( Array * arrayOfAnimationFrames , float delayPerUnit , unsigned int loops ) ;
2012-04-19 14:35:52 +08:00
2013-06-19 06:06:53 +08:00
/** returns a clone fo the animation */
2013-06-20 14:13:12 +08:00
virtual Animation * clone ( ) const ;
2013-06-19 06:06:53 +08:00
2013-06-20 14:13:12 +08:00
/** total Delay units of the Animation. */
2013-06-15 14:03:30 +08:00
CC_SYNTHESIZE_READONLY ( float , _totalDelayUnits , TotalDelayUnits )
2012-04-19 14:35:52 +08:00
/** Delay in seconds of the "delay unit" */
2013-06-15 14:03:30 +08:00
CC_SYNTHESIZE ( float , _delayPerUnit , DelayPerUnit )
2012-04-19 14:35:52 +08:00
/** duration in seconds of the whole animation. It is the result of totalDelayUnits * delayPerUnit */
2013-06-15 14:03:30 +08:00
CC_PROPERTY_READONLY ( float , _duration , Duration )
2012-04-19 14:35:52 +08:00
2013-06-20 14:13:12 +08:00
/** array of AnimationFrames */
CC_SYNTHESIZE_RETAIN ( Array * , _frames , Frames )
2012-04-19 14:35:52 +08:00
/** whether or not it shall restore the original frame when the animation finishes */
2013-06-15 14:03:30 +08:00
CC_SYNTHESIZE ( bool , _restoreOriginalFrame , RestoreOriginalFrame )
2012-04-19 14:35:52 +08:00
/** how many times the animation is going to loop. 0 means animation is not animated. 1, animation is executed one time, ... */
2013-06-15 14:03:30 +08:00
CC_SYNTHESIZE ( unsigned int , _loops , 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__