本文主要是介绍CCArmature(骨骼动画),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
DRAGONBONES 官方C++版本 FOR COCOS2D-X
在COCOS2D-X中使用CCARMATURE实现骨骼动画
在 QUICK-COCOS2D-X 中使用 DRAGONBONESCPP
cocos2d-x专用的DragonBones2.2
cocos2d-x 骨骼动画详解
Cocos Studio -- 骨骼动画与简单碰撞
例子:
local manager = CCArmatureDataManager:sharedArmatureDataManager()manager:addArmatureFileInfo(PathManager:getDrawMov(self.sourceName..".png"),PathManager:getDrawMov(self.sourceName..".plist"),PathManager:getDrawMov(self.sourceName..".xml"))
self.dragon = CCArmature:create("drawOneMovie")
self.animation = self.dragon:getAnimation()
self.animation:setSpeedScale(24 / 60) -- Flash fps is 24, cocos2d-x is 60
self.animation:play("play")
self.dragon:addTo(self)
self.dragon:setPosition(self:convertToNodeSpace(ccp(display.cx, display.cy)) )
--事件回调
self.animation:setFrameEventCallFunc(handler(self, self.onDrawOneMovieFrameCall));self.animation:setMovementEventCallFunc(handler(self, self.onPlayComplete));
--frameEventName 帧事件名字 flash里设置 或者到self.sourceName..".xml" 手动加evt="xxx"
function treasureboxPlayer:onDrawOneMovieFrameCall(bone,frameEventName, originFrameIndex, currentFrameIndex) 。。end
function treasureboxPlayer:onPlayComplete(pArmature, eventType, animationID)
if eventType == enumArmatureAnimationMovementEventType.COMPLETE then
self:updateListeners("end") --
end
end
self.dragon:getBone("bigDrop"):changeDisplayWithIndex(0,false)
else
self.dragon:getBone("bigDrop"):changeDisplayWithIndex(-1,true)
end
local dragon = CCArmature:create("backlight1")
if dragon then
local bone_backlight = CCBone:create("xxx")
local animation = dragon:getAnimation()
animation:setSpeedScale(24 / 60) -- Flash fps is 24, cocos2d-x is 60
animation:play("play")
dragon:setPosition(55,-55)
bone_backlight:addDisplay(dragon ,0)
bone_backlight:changeDisplayWithIndex(0,true)
self.dragon:addBone(bone_backlight, "bone1")
end
--监听 包围盒获得函数不同于node boundingBox = obj:getDisplayManager():getBoundingBox()
bone.idx = "bone"
self:addTouchEventListener(bone , handler(self,self.onClickDropIcon) ,Bone_tag )
xxx:isContainsPoint(obj, point)local boundingBox
if obj.idx == "bone" then
boundingBox = obj:getDisplayManager():getBoundingBox()
else
boundingBox = tolua.cast(obj, "CCNode"):boundingBox()
end
if boundingBox:containsPoint(tolua.cast(obj:getParent(), "CCNode"):convertToNodeSpace(point)) then
xxx
end
end
self.animation:playWithIndex(0)
self.animation:gotoAndPlay(0); -- 参数就是flash 里 帧的 index
--self.animation:stop()
--self.animation:play("play")
--cocos好像不自动释放缓存文件
CCArmatureDataManager:sharedArmatureDataManager():removeArmatureFileInfo(PathManager:getDrawMov(self.sourceName..".xml"));CCSpriteFrameCache:sharedSpriteFrameCache():removeSpriteFramesFromFile(PathManager:getDrawMov(self.sourceName..".plist"));
CCTextureCache:sharedTextureCache():removeTextureForKey(PathManager:getDrawMov(self.sourceName..".png"));
class CCArmature : public CCNodeRGBA, public CCBlendProtocol
{
public:
static CCArmature *create();
//Allocates a armature, and use the CCArmatureData named name in CCArmatureDataManager to initializes the armature.
static CCArmature *create(const char *name); //创建之前先要将骨骼资源载入CCArmatureDataManager
static CCArmature *create(const char *name, CCBone *parentBone);
virtual void addBone(CCBone *bone, const char* parentName);//添加子骨骼 1、需要添加的骨骼 2、父骨骼的名字 内部调用了 bone:addChildBone
virtual CCBone *getBone(const char *name) const;
virtual void changeBoneParent(CCBone *bone, const char *parentName);
virtual void removeBone(CCBone *bone, bool recursion);
virtual CCRect boundingBox();//计算所有bone包围盒 得到整个CCArmature包围盒。 用于计算碰撞和触摸
CCBone *getBoneAtPoint(float x, float y);
};
class CC_EX_DLLCCArmatureAnimation :public CCProcessBase
{
public:
* Create with a CCArmature
* @param armature The CCArmature CCArmatureAnimation will bind to
staticCCArmatureAnimation *create(CCArmature *armature);
public:
/**
* Scale animation play speed.
* @param animationScale Scale value
*/
virtualvoid setSpeedScale(float speedScale);
virtualfloat getSpeedScale()const;
//! The animation update speed
CC_DEPRECATED_ATTRIBUTEvirtual void setAnimationInternal(float animationInternal) {};
usingCCProcessBase::play;
/**
* Play animation by animation name.
*
* @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
*
* -1 : use the value from CCMovementData get from flash design panel
* @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
*
* -1 : use the value from CCMovementData get from flash design panel
*
* @param loop Whether the animation is loop
*
* loop < 0 : use the value from CCMovementData get from flash design panel
* loop = 0 : this animation is not loop
* loop > 0 : this animation is loop
*
* @param tweenEasing CCTween easing is used for calculate easing effect
*
* TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel
* -1 : fade out
* 0 : line
* 1 : fade in
* 2 : fade in and out
*
*/
virtualvoid play(constchar *animationName,int durationTo = -1,int durationTween = -1, int loop = -1,int tweenEasing = TWEEN_EASING_MAX);
virtualvoid playWithIndex(int animationIndex, int durationTo = -1,int durationTween = -1, int loop = -1,int tweenEasing =TWEEN_EASING_MAX);
virtualvoid playWithNames(conststd::vector<std::string>& movementNames,int durationTo = -1,bool loop =true);
/**
* Play several animation by indexes
*/
virtualvoid playWithIndexes(conststd::vector<int>& movementIndexes,int durationTo = -1,bool loop =true);
// For bindings
virtualvoid playWithArray(cocos2d::CCArray *movementNames,int durationTo = -1,bool loop = true);
virtualvoid playWithIndexArray(cocos2d::CCArray *movementIndexes,int durationTo = -1,bool loop = true);
virtualvoid gotoAndPlay(int frameIndex);
virtual void gotoAndPause(int frameIndex);
virtualvoid pause();
virtualvoid resume();
virtualvoid stop();
int getMovementCount();
void update(float dt);
std::string getCurrentMovementID();
/**
* Set armature's movement event callback function
* To disconnect this event, just setMovementEventCallFunc(NULL, NULL);
*/
void setMovementEventCallFunc(CCObject *target,SEL_MovementEventCallFunc callFunc);
/**
* Set armature's frame event callback function
* To disconnect this event, just setFrameEventCallFunc(NULL, NULL);
*/
void setFrameEventCallFunc(CCObject *target,SEL_FrameEventCallFunc callFunc);
};
classCC_EX_DLLCCBone :publicCCNode
{
public:
staticCCBone *create();
staticCCBone *create(constchar *name);
public:
/**
* Add display and use displayData to init the display.
* If index already have a display, then replace it.
* If index is current display index, then also change display to _index
*
* @param displayData it include the display information, like DisplayType.
* If you want to create a sprite display, then create a CCSpriteDisplayData param
*
* @param index the index of the display you want to replace or add to
* -1 : append display from back
*/
void addDisplay(CCDisplayData *displayData,int index);
void addDisplay(CCNode *display,int index);
void removeDisplay(int index);
void changeDisplayWithIndex(int index,bool force);
void changeDisplayWithName(constchar *name,bool force);
void addChildBone(CCBone *child);
void setParentBone(CCBone *parent);
CCBone *getParentBone();
usingCCNode::removeFromParent;
void removeFromParent(bool recursion);
void removeChildBone(CCBone *bone,bool recursion);
void update(float delta);
void updateDisplayedColor(constccColor3B &parentColor);
void updateDisplayedOpacity(GLubyte parentOpacity);
void setColor(constccColor3B &color);
void setOpacity(GLubyte opacity);
//! Update color to render display
void updateColor();
//! Update zorder
void updateZOrder();
virtualvoid setZOrder(int zOrder);
public:
/*
* The origin state of the CCBone. Display's state is effected by m_pBoneData, m_pNode, m_pTweenData
* when call setData function, it will copy from the CCBoneData.
*/
CC_PROPERTY(CCBoneData *, m_pBoneData, BoneData);
//! A weak reference to the CCArmature
CC_PROPERTY(CCArmature *, m_pArmature, Armature);
//! A weak reference to the child CCArmature
CC_PROPERTY(CCArmature *, m_pChildArmature, ChildArmature);
CC_SYNTHESIZE(CCDisplayManager *,m_pDisplayManager, DisplayManager)
/*
* When CCArmature play an animation, if there is not a CCMovementBoneData of this bone in this CCMovementData, this bone will be hidden.
* Set IgnoreMovementBoneData to true, then this bone will also be shown.
*/
CC_SYNTHESIZE(bool,m_bIgnoreMovementBoneData, IgnoreMovementBoneData)
};
/**! CCDisplayManager manages CCBone's display*/
class CC_EX_DLLCCDisplayManager :publicCCObject
{
public:
staticCCDisplayManager *create(CCBone *bone);
public:
bool init(CCBone *bone);
/**
* Use CCBoneData to init the display list.
* If display is a sprite, and it have texture info in the TexutreData, then use TexutreData to init the display's anchor point
* If the display is a CCArmature, then create a new CCArmature
*/
virtualvoid initDisplayList(CCBoneData *boneData);
/**
* Add display and use _DisplayData init the display.
* If index already have a display, then replace it.
* If index is current display index, then also change display to _index
*
* @paramdisplayData it include the display information, like DisplayType.
* If you want to create a sprite display, then create a CCSpriteDisplayData param
*
* @paramindex the index of the display you want to replace or add to
* -1 : append display from back
*/
void addDisplay(CCDisplayData *displayData,int index);
void addDisplay(CCNode *display,int index);
void removeDisplay(int index);
CCArray *getDecorativeDisplayList();
* Change display by index. You can just use this method to change display in the display list.
* The display list is just used for this bone, and it is the displays you may use in every frame.
*
* Note : if index is the same with prev index, the method will not effect
*
* @param index The index of the display you want to change
* @param force If true, then force change display to specified display, or current display will set to display index edit in the flash every key frame.
*/
void changeDisplayWithIndex(int index,bool force);
void changeDisplayWithName(constchar *name,bool force);
int getCurrentDisplayIndex();
virtualvoid setCurrentDecorativeDisplay(CCDecorativeDisplay *decoDisplay);
virtualCCDecorativeDisplay *getCurrentDecorativeDisplay();
virtualCCDecorativeDisplay *getDecorativeDisplayByIndex(int index);
/**
* Sets whether the display is visible
* The default value is true, a node is default to visible
*
* @param visible true if the node is visible, false if the node is hidden.
*/
virtualvoid setVisible(bool visible);
/**
* Determines if the display is visible
*
* @see setVisible(bool)
* @return true if the node is visible, false if the node is hidden.
*/
virtualbool isVisible();
CCSize getContentSize();
CCRect getBoundingBox();//处理bone的触摸时通过这个函数获得包围盒
CCPoint getAnchorPoint();
CCPoint getAnchorPointInPoints();
/**
* Check if the position is inside the bone.
*/
virtualbool containPoint(CCPoint &_point);
/**
* Check if the position is inside the bone.
*/
virtualbool containPoint(float x,float y);
protected:
CCBone *m_pBone;
};
这篇关于CCArmature(骨骼动画)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!