2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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 __CCANIMATION_H__
|
|
|
|
#define __CCANIMATION_H__
|
|
|
|
|
|
|
|
#include "CCProcessBase.h"
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocostudio {
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 14:47:08 +08:00
|
|
|
|
2013-06-07 16:13:08 +08:00
|
|
|
enum MovementEventType
|
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
START,
|
|
|
|
COMPLETE,
|
|
|
|
LOOP_COMPLETE
|
2013-06-07 16:13:08 +08:00
|
|
|
};
|
2013-06-07 14:47:08 +08:00
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
class Armature;
|
|
|
|
class Bone;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
typedef void (cocos2d::Object::*SEL_MovementEventCallFunc)(Armature *, MovementEventType, const char *);
|
|
|
|
typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const char *, int, int);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
#define movementEvent_selector(_SELECTOR) (SEL_MovementEventCallFunc)(&_SELECTOR)
|
|
|
|
#define frameEvent_selector(_SELECTOR) (SEL_FrameEventCallFunc)(&_SELECTOR)
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
class ArmatureAnimation : public ProcessBase
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Create with a Armature
|
|
|
|
* @param armature The Armature ArmatureAnimation will bind to
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
static ArmatureAnimation *create(Armature *armature);
|
2013-06-06 12:02:54 +08:00
|
|
|
public:
|
2013-09-16 14:13:55 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureAnimation();
|
2013-09-16 14:13:55 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
virtual ~ArmatureAnimation(void);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
/**
|
2013-09-15 19:08:45 +08:00
|
|
|
* Init with a Armature
|
|
|
|
* @param armature The Armature ArmatureAnimation will bind to
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
virtual bool init(Armature *armature);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Scale animation play speed.
|
2013-06-06 12:02:54 +08:00
|
|
|
* @param animationScale Scale value
|
|
|
|
*/
|
2013-06-07 10:52:32 +08:00
|
|
|
virtual void setAnimationScale(float animationScale);
|
2013-09-13 18:07:37 +08:00
|
|
|
virtual float getAnimationScale() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale animation play speed.
|
|
|
|
* @param animationScale Scale value
|
|
|
|
*/
|
|
|
|
virtual void setSpeedScale(float speedScale);
|
|
|
|
virtual float getSpeedScale() const;
|
|
|
|
|
|
|
|
//! The animation update speed
|
|
|
|
virtual void setAnimationInternal(float animationInternal);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Play animation by animation name.
|
2013-06-06 12:02:54 +08:00
|
|
|
*
|
|
|
|
* @param animationName The animation name you want to play
|
|
|
|
* @param durationTo The frames between two animation changing-over.
|
|
|
|
* It's meaning is changing to this animation need how many frames
|
|
|
|
*
|
2013-09-15 19:08:45 +08:00
|
|
|
* -1 : use the value from MovementData get from flash design panel
|
2013-06-06 12:02:54 +08:00
|
|
|
* @param durationTween The frame count you want to play in the game.
|
|
|
|
* if _durationTween is 80, then the animation will played 80 frames in a loop
|
|
|
|
*
|
2013-09-15 19:08:45 +08:00
|
|
|
* -1 : use the value from MovementData get from flash design panel
|
2013-06-06 12:02:54 +08:00
|
|
|
*
|
|
|
|
* @param loop Whether the animation is loop
|
|
|
|
*
|
2013-09-15 19:08:45 +08:00
|
|
|
* loop < 0 : use the value from MovementData get from flash design panel
|
2013-06-06 12:02:54 +08:00
|
|
|
* loop = 0 : this animation is not loop
|
|
|
|
* loop > 0 : this animation is loop
|
|
|
|
*
|
2013-09-15 19:08:45 +08:00
|
|
|
* @param tweenEasing Tween easing is used for calculate easing effect
|
2013-06-06 12:02:54 +08:00
|
|
|
*
|
2013-09-15 19:08:45 +08:00
|
|
|
* TWEEN_EASING_MAX : use the value from MovementData get from flash design panel
|
2013-06-06 12:02:54 +08:00
|
|
|
* -1 : fade out
|
|
|
|
* 0 : line
|
|
|
|
* 1 : fade in
|
|
|
|
* 2 : fade in and out
|
|
|
|
*
|
|
|
|
*/
|
2013-06-07 10:52:32 +08:00
|
|
|
void play(const char *animationName, int durationTo = -1, int durationTween = -1, int loop = -1, int tweenEasing = TWEEN_EASING_MAX);
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Play animation by index, the other param is the same to play.
|
2013-09-13 18:07:37 +08:00
|
|
|
* @param _animationIndex the animation index you want to play
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
|
|
|
void playByIndex(int animationIndex, int durationTo = -1, int durationTween = -1, int loop = -1, int tweenEasing = TWEEN_EASING_MAX);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Pause the Process
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-06-07 10:52:32 +08:00
|
|
|
virtual void pause();
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Resume the Process
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-06-07 10:52:32 +08:00
|
|
|
virtual void resume();
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Stop the Process
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-06-07 10:52:32 +08:00
|
|
|
virtual void stop();
|
|
|
|
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Get movement count
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
|
|
|
int getMovementCount();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
void update(float dt);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current movementID
|
|
|
|
* @return The name of current movement
|
|
|
|
*/
|
|
|
|
std::string getCurrentMovementID();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set armature's movement event callback function
|
|
|
|
* To disconnect this event, just setMovementEventCallFunc(NULL, NULL);
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void setMovementEventCallFunc(cocos2d::Object *target, SEL_MovementEventCallFunc callFunc);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set armature's frame event callback function
|
|
|
|
* To disconnect this event, just setFrameEventCallFunc(NULL, NULL);
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
protected:
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Update(float dt) will call this handler, you can handle your logic here
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
|
|
|
void updateHandler();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/**
|
2013-06-07 10:52:32 +08:00
|
|
|
* Update current key frame, and process auto stop, pause
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-06-07 10:52:32 +08:00
|
|
|
void updateFrameData(float currentPercent);
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
/**
|
|
|
|
* Emit a frame event
|
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
friend class Tween;
|
2013-06-06 12:02:54 +08:00
|
|
|
protected:
|
2013-09-15 19:08:45 +08:00
|
|
|
//! AnimationData save all MovementDatas this animation used.
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SYNTHESIZE_RETAIN(AnimationData *, _animationData, AnimationData);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
//! Scale the animation speed
|
2013-09-15 20:24:25 +08:00
|
|
|
float _speedScale;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
MovementData *_movementData; //! MovementData save all MovementFrameDatas this animation used.
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
Armature *_armature; //! A weak reference of armature
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
std::string _movementID; //! Current movment's name
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
int _toIndex; //! The frame index in MovementData->m_pMovFrameDataArr, it's different from m_iFrameIndex.
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Array *_tweenList;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
protected:
|
2013-06-07 10:52:32 +08:00
|
|
|
/**
|
2013-09-13 18:07:37 +08:00
|
|
|
* MovementEvent CallFunc.
|
2013-09-15 19:08:45 +08:00
|
|
|
* @param Armature* a Armature
|
2013-09-13 18:07:37 +08:00
|
|
|
* @param MovementEventType, Event Type, like START, COMPLETE.
|
|
|
|
* @param const char*, Movement ID, also called Movement Name
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-09-15 20:24:25 +08:00
|
|
|
SEL_MovementEventCallFunc _movementEventCallFunc;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FrameEvent CallFunc.
|
2013-09-15 19:08:45 +08:00
|
|
|
* @param Bone*, a Bone
|
2013-09-13 18:07:37 +08:00
|
|
|
* @param const char*, the name of this frame event
|
|
|
|
* @param int, origin frame index
|
|
|
|
* @param int, current frame index, animation may be delayed
|
|
|
|
*/
|
2013-09-15 20:24:25 +08:00
|
|
|
SEL_FrameEventCallFunc _frameEventCallFunc;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Object *_movementEventTarget;
|
|
|
|
cocos2d::Object *_frameEventTarget;
|
2013-06-06 12:02:54 +08:00
|
|
|
};
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
#endif /*__CCANIMATION_H__*/
|