Egret之龙骨卡槽(slot)换皮
admin
2023-02-17 14:00:09
0

龙骨的图片是绑定在卡槽上的.并且是一对一的关系.所以可以通过对骨架的卡槽上绑定的图片的更换来实现另一种换皮的效果.

换皮的核心代码:

    //针对slot设置其新内容
    private setNewSlot( slotName:string, textureName:string )
    {
        //方法1
        var slot:dragonBones.Slot = this._armature.getSlot( slotName );
        var b:egret.Bitmap = new egret.Bitmap();
        b.texture = RES.getRes( textureName );
        b.x = slot.display.x;
        b.y = slot.display.y;
        b.anchorOffsetX = b.width/2;
        b.anchorOffsetY = b.height/2;
        slot.setDisplay( b );

        //方法2,仅限于slot中内容为Bitmap
        //var slot:dragonBones.Slot = this._armature.getSlot(slotName);
        //slot.display.texture = RES.getRes(textureName);
    }

我做了一个工具:

module bg2tool{
    /**
     * 龙骨动画工具--单例
     * @author Husz
     */
    export class DragonBoneAnimationTools{
        private static _instance : DragonBoneAnimationTools = null;

        /**
         * 获取单例(只读......)
         * @returns {bg2tool.DragonBoneAnimationTools}
         * @constructor
         */
        public static get Instance() : DragonBoneAnimationTools{
            if( DragonBoneAnimationTools._instance == null ){
                DragonBoneAnimationTools._instance = new DragonBoneAnimationTools();
            }
            return DragonBoneAnimationTools._instance;
        }

        /**
         * 防止类外实例化
         */
        private constructor(){}

        /**
         * 设置骨骼卡槽的皮肤
         * @param {dragonBones.EgretArmatureDisplay} $animation 骨骼动画
         * @param {string} $slotName 卡槽名称
         * @param {string} $textureName 纹理
         */
        public setNewSlot( $animation : dragonBones.EgretArmatureDisplay ,  $slotName:string, $textureName:string ) : void{
            if( DEBUG ){
                if( !RES.hasRes($textureName) ){
                    egret.error(`骨骼动画卡槽换装 ${$textureName} 纹理没有配置!!!`);
                }else{
                    if( RES.getRes( $textureName ) == null ){
                        egret.error(`骨骼动画卡槽换装 ${$textureName} 纹理没有被加载!!!`);
                    }
                }
            }
            let slot:dragonBones.Slot = $animation.armature.getSlot($slotName);
            let b:egret.Bitmap = new egret.Bitmap();
            b.texture = RES.getRes( $textureName );
            b.x = slot.display.x;
            b.y = slot.display.y;
            b.anchorOffsetX = b.width>>1;
            b.anchorOffsetY = b.height>>1;
            slot.display = b;
        }
    }
}

现在准备测试

①: 准备龙骨资源
Egret之龙骨卡槽(slot)换皮

注意:
球的图片资源绑定的卡槽名称为 slot
Egret之龙骨卡槽(slot)换皮

看看初始骨骼动画效果:

private $dragonBone : dragonBones.EgretArmatureDisplay = null;
                this.$dragonBone = bg2tool.DragonBonePoolResManager.Instance.getAnimation4DragonBone(
                    "GuajiSelfBone_ske_json",
                    "GuajiSelfBone_tex_json",
                    "GuajiSelfBone_tex_png",
                    "guajiAnimation",
                    1,
                    1
                );
                this._context.GuajiAnimation.addChild( this.$dragonBone );

                this.$dragonBone.x = 200;
                this.$dragonBone.y = 400;

                this.$dragonBone.animation.play("jumping",0);

结果:
Egret之龙骨卡槽(slot)换皮

换皮开始:
换成:
Egret之龙骨卡槽(slot)换皮

代码:

                this.$dragonBone = bg2tool.DragonBonePoolResManager.Instance.getAnimation4DragonBone(
                    "GuajiSelfBone_ske_json",
                    "GuajiSelfBone_tex_json",
                    "GuajiSelfBone_tex_png",
                    "guajiAnimation",
                    1,
                    1
                );
                this._context.GuajiAnimation.addChild( this.$dragonBone );

                this.$dragonBone.x = 200;
                this.$dragonBone.y = 400;

                this.$dragonBone.animation.play("jumping",0);

                bg2tool.ResSyncLoadingManager.Instance.startLoading( "1-1_99003_png" , this.changeSkin.bind(this) );

                        private changeSkin( $skin : string ) : void{
                                    if( $skin == "1-1_99003_png" ){
                                            bg2tool.DragonBoneAnimationTools.Instance.setNewSlot( this.$dragonBone , "slot" , $skin );
                                    }
        }

结果 :
Egret之龙骨卡槽(slot)换皮

相关内容

热门资讯

【第一消息】“小南长牌有没有挂... 您好:小南长牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游戏...
终于了解“情缘怎么装挂?”(果... 家人们!今天小编来为大家解答情缘透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很多人...
有意思!成都这些建筑是“算”出... 当你置身于成都凤凰山体育公园那舒展的“飞檐”之下,或是仰望东安湖体育公园屋面上巨大的太阳神鸟,抑或在...
我来教教您“约约麻将可以开挂吗... 您好:约约麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏...
巴拿马总统府:立即在原址修复华... 新华社巴拿马城12月28日电(记者许咏政) 巴拿马总统府28日发布公告,明确反对拆毁位于巴拿马运河西...
中到大雪!暴雪!31日河南将迎... 河南即将迎来跨年雪30日夜里到31日雨雪在线随着冷空气与暖湿气流的交汇,明天夜里开始,我省将有新一轮...
为绿水青山筑起“智慧”防线 近日,在黑龙江省通北林业局的广袤林区,一架无人机按照预设程序自动从机巢起飞,开始日常巡护。它传回的高...
今日重磅消息“朋友安徽麻将开挂... 网上科普关于“朋友安徽麻将有没有挂”话题很是火热,小编也是针对朋友安徽麻将作*弊开挂的方法以及开挂对...
当AI进入下半场,海珠迎来解题... 十多年前,在海外读书的广州佳知慧行科技有限公司总经理王凯曾和同学一起驱车深入沙漠,参与一场火箭的发射...
今日重大通报“普通扑克三公提前... 家人们!今天小编来为大家解答普通扑克三公提前知道大小透视挂怎么安装这个问题咨询软件客服徽978409...