Egret之龙骨换装

需求:

wKiom1m-geTwXOGpAALT4YhVZd8525.png-wh_50

找到了黄马褂的结构:

wKioL1m-gc_R-t5kAAE7LeE53WY060.png-wh_50

 

我们新建一个DragonBones项目 , 用以为上述黄马褂换肤

wKioL1m-gqmhFzcuAAIsIfIYyIU839.png-wh_50

我们对DragonE_view进行修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
///<reference path="./../tools/DragonBoneTools.ts" />
module app {
  export class DragonE_View  extends eui.Component implements eui.UIComponent {
   private com_dragon : eui.Group;
   private img_dragon : eui.Image;
   private txt_name : eui.Label;
         private egretFactory : dragonBones.EgretFactory;
         private eff_robot : dragonBones.EgretArmatureDisplay;
   public constructor() {
    super ();
    this .skinName =  "resource/eui_skins/DragonE.exml" ;
   }
   protected partAdded(partName : string , instance : any):void{
    super .partAdded(partName , instance);
   }
   protected childrenCreated():void{
    super .childrenCreated();
    this .txt_name.text =  "Snow" ;
    this .img_dragon.source = RES.getRes( "egret_icon_png" );
    this .playDragonEff();
   }
   /**
          *刷新机器人特效
          */
         public playDragonEff(): void {
             // this.loadChibangByResName("Robot_json");
             this .loadChibangByResName( "Dragon_ske_json" );
         }
   /**
          * 异步Robot动画资源
          */
         private loadChibangByResName(name: string): void {
             var  self =  this ;
             RES.getResAsync(name,
                 function (data: any,key: string): void {
                     if (key ==  "Dragon_ske_json" ) {
                         self.loadChibangByResName( "Dragon_tex_json" );
                     }
                     else  if (key ==  "Dragon_tex_json" ) {
                         self.loadChibangByResName( "Dragon_tex_png" );
                     }
                     else  if (key ==  "Dragon_tex_png" ) {
                         this .showRoleWing();
                     }
                 },
                 this );
         }
 
   /**
         * 展示Robot特效
         */
         private showRoleWing(wingId: number): void {
             this .egretFactory = tools.DragonBoneTools.Instance.createEff2New(
                 "Dragon_ske_json" ,
                 "Dragon_tex_json" ,
                 "Dragon_tex_png" ,
                 );
             this .eff_robot =  this .egretFactory.buildArmatureDisplay( "Dragon" );
             this .addChild( this .eff_robot);
             this .eff_robot.animation.play( "jump" ,0);
             this .eff_robot.x = 200;
             this .eff_robot.y = 450;
            
              this .stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this .onTouch, this );
         }
         private onTouch(evt: egret.TouchEvent) : void{
             if (evt.type == egret.TouchEvent.TOUCH_BEGIN)
             {
                 this .changeClothes();
             }
         }
         private changeClothes():void{
             this .loadChangeByResName( "DragonChange_ske_json" );
         }
         private loadChangeByResName(name : string) : void{
             var  self =  this ;
             RES.getResAsync(name,
                 function (data: any,key: string): void {
                     if (key ==  "DragonChange_ske_json" ) {
                         self.loadChangeByResName( "DragonChange_tex_json" );
                     }
                     else  if (key ==  "DragonChange_tex_json" ) {
                         self.loadChangeByResName( "DragonChange_tex_png" );
                     }
                     else  if (key ==  "DragonChange_tex_png" ) {
                         this .changeRoleWing();
                     }
                 },
                 this );
         }
         private changeRoleWing():void{
             this .egretFactory.parseDragonBonesData(RES.getRes( "DragonChange_ske_json" ));
             this .egretFactory.parseTextureAtlasData(RES.getRes( "DragonChange_tex_json" ), RES.getRes( "DragonChange_tex_png" ));
             this .egretFactory.replaceSlotDisplay(  "DragonChange" "Armature" "clothes2" "clothes2" this .eff_robot.armature.getSlot( "clothes" ));
         }
  }
}

重点 :

            this.egretFactory.parseDragonBonesData(RES.getRes("DragonChange_ske_json"));
            this.egretFactory.parseTextureAtlasData(RES.getRes("DragonChange_tex_json"), RES.getRes("DragonChange_tex_png"));
            this.egretFactory.replaceSlotDisplay( "DragonChange", "Armature", "clothes2", "clothes2", this.eff_robot.armature.getSlot("clothes"));


replaceSlotDisplay : 替换一个骨头的显示

第一个参数 : 替换项目的名称

第二个参数 : 替换目场景名字

第三个参数 : 替换项目的骨骼名字

第五个参数 : 替换项目的图片名字

第五个参数 : 被替换项目的卡槽


结果 :

wKiom1m-hJCSDQL-AAH4rPl2-Fg252.png-wh_50


全局换装 ::://将图集全部替换

ar.armature.replaceTexture(RES.getRes("new_db_texture_png"));














本文转自Aonaufly51CTO博客,原文链接: http://blog.51cto.com/aonaufly/1966134,如需转载请自行联系原作者



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值