cocos 点击遍历播放该骨骼所有动画

本文介绍如何在Cocos2d-x中使用dragonBones组件实现骨骼动画的循环播放,通过注册监听事件在动画结束后自动播放下一个动画,直到所有动画播放完毕。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

cc.Class({
    extends: cc.Component,

    properties: {
        _musicVolume: 1.0,
        _playEffect: [],
        _switchEffect: true
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.arr = new Array();
        this.count = 0;
        this.node.on('touchstart',  (event) => {
            // 骨骼动画复制
            this.donghua = this.node.getChildByName("touch").getComponent(dragonBones.ArmatureDisplay);
            // 注册监听事件
            this.donghua.addEventListener(dragonBones.EventObject.COMPLETE, this._animationEventHandler, this);
            // 播放第一个动画,动画结束时调监听事件
            this.donghua.playAnimation("walk",1);
            // 获取该骨骼所有动画名称
            this.arr = this.donghua.getAnimationNames("armatureName");
            cc.log("动画名称:" + this.arr);

        });

    },

    _animationEventHandler: function(event) {
        cc.log("动画开始播放 = " + this.arr[this.count]);
        this.donghua.playAnimation(this.arr[this.count],1);
        this.donghua.addEventListener(dragonBones.EventObject.COMPLETE, this._animationEventHandler, this);
        this.count++;
        if (this.count>this.arr.length-1)
        {
            cc.log("动画已经全部播放!");
            // 播放结束以后,删除事件
            this.donghua.removeEventListener(dragonBones.EventObject.COMPLETE, this._animationEventHandler, this);
            return ;
        }
    },

    
    start () {

    },


    // update (dt) {},
});

 

转载于:https://www.cnblogs.com/Hunter-541695/p/9852891.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值