CCArmature(骨骼动画)

2024-01-30 21:08
文章标签 动画 骨骼 ccarmature

本文主要是介绍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


    if xx  then--隐藏显示bone
self.dragon:getBone("bigDrop"):changeDisplayWithIndex(0,false)   
else
self.dragon:getBone("bigDrop"):changeDisplayWithIndex(-1,true)
end


        -- 加入子bone
        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


         --动画跳到0帧
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 = -1int loop = -1,int tweenEasing = TWEEN_EASING_MAX);


   virtualvoid playWithIndex(int animationIndex, int durationTo = -1,int durationTween = -1int 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(骨骼动画)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/661559

相关文章

最好用的WPF加载动画功能

《最好用的WPF加载动画功能》当开发应用程序时,提供良好的用户体验(UX)是至关重要的,加载动画作为一种有效的沟通工具,它不仅能告知用户系统正在工作,还能够通过视觉上的吸引力来增强整体用户体验,本文给... 目录前言需求分析高级用法综合案例总结最后前言当开发应用程序时,提供良好的用户体验(UX)是至关重要

基于Python实现PDF动画翻页效果的阅读器

《基于Python实现PDF动画翻页效果的阅读器》在这篇博客中,我们将深入分析一个基于wxPython实现的PDF阅读器程序,该程序支持加载PDF文件并显示页面内容,同时支持页面切换动画效果,文中有详... 目录全部代码代码结构初始化 UI 界面加载 PDF 文件显示 PDF 页面页面切换动画运行效果总结主

Qt QWidget实现图片旋转动画

《QtQWidget实现图片旋转动画》这篇文章主要为大家详细介绍了如何使用了Qt和QWidget实现图片旋转动画效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、效果展示二、源码分享本例程通过QGraphicsView实现svg格式图片旋转。.hpjavascript

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

用Unity2D制作一个人物,实现移动、跳起、人物静止和动起来时的动画:中(人物移动、跳起、静止动作)

上回我们学到创建一个地形和一个人物,今天我们实现一下人物实现移动和跳起,依次点击,我们准备创建一个C#文件 创建好我们点击进去,就会跳转到我们的Vision Studio,然后输入这些代码 using UnityEngine;public class Move : MonoBehaviour // 定义一个名为Move的类,继承自MonoBehaviour{private Rigidbo

动画AnimationDrawable、转动

现实开发中:很多地方都用到 点击动画的特效; 本案例本人做了三个关于“动” 画 的效果; 先上图: 总体图: A: B: 1:点击图片按钮,效果是:图片闪动; 通过在xml中定义:标签:animation-list来实现点击动画的效果;  是否循环标签:oneshot ;   时间间隔标签:duration ; 要显示的图片标签:drawable ;

13 transition数组的动画使用

划重点 动画:transitiontransition-group :数组动画数组的 添加 / 删除 豆腐粉丝汤 清淡又健康 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><me

12 动画transition的使用2

划重点 Vue 动画:transition / transform在动画周期中执行动动画(上一篇是通过动画样式控制动画) 清蒸扇贝 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><

【前端】animation动画以及利用vue制作简单的透明度改变动画,包含vue生命周期实现

一. 问题描述 想做一个文字透明度从1到0然后再从0到1的css动画。 二. 代码写法 2.1 animation写法 2.1.1 animation属性key 2.1.2 代码展示 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=de