CocosCreator骨骼動畫之龍骨DragonBones
CocosCreator版本2.3.4
龍骨動畫
將龍骨動畫放到cocos的assets下。我這裡龍骨動畫是Dragonbones導出的二進制動畫。
直接拖拽龍骨動畫(骨頭圖標)到舞臺
設置骨骼動畫的屬性,DragonAltasAsset圖片,Animation動作,PlayTime循環播放等
代碼生成龍骨動畫
龍骨資源路徑是assets/resources/dragonbones,loadResDir隻需要填dragonbones就行瞭。
//根據路徑加載資源 cc.loader.loadResDir("dragonbones",cc.Asset,null,(err, resource)=>{ console.log("資源:",resource); //生成骨骼動畫 let node:cc.Node = new cc.Node(); let armatureDisplay:dragonBones.ArmatureDisplay = node.addComponent(dragonBones.ArmatureDisplay); armatureDisplay.dragonAsset = resource[0]; armatureDisplay.dragonAtlasAsset = resource[3]; armatureDisplay.armatureName = "role3"; armatureDisplay.playAnimation("move",0); node.x = 100; node.y = 100; this.node.addChild(node); });
替換皮膚
//加載資源 cc.loader.loadResDir("dragonbones",cc.Asset,null,(err, resource)=>{ console.log("資源:",resource); //生成動畫1 let node:cc.Node = new cc.Node(); let armatureDisplay:dragonBones.ArmatureDisplay = node.addComponent(dragonBones.ArmatureDisplay); armatureDisplay.dragonAsset = resource[0]; armatureDisplay.dragonAtlasAsset = resource[3]; armatureDisplay.armatureName = "role3"; armatureDisplay.playAnimation("move",0); node.x = 100; node.y = 100; this.node.addChild(node); //生成動畫2 let node2:cc.Node = new cc.Node(); let armatureDisplay2:dragonBones.ArmatureDisplay = node2.addComponent(dragonBones.ArmatureDisplay); armatureDisplay2.dragonAsset = resource[4]; armatureDisplay2.dragonAtlasAsset = resource[7]; armatureDisplay2.armatureName = "role4"; armatureDisplay2.playAnimation("move",0); node2.x = 150; node2.y = 150; this.node.addChild(node2); //動畫2的皮膚應用到動畫1上 let factory = dragonBones.CCFactory.getInstance(); factory.replaceSkin(armatureDisplay.armature(), (armatureDisplay2.armature() as dragonBones.Armature).armatureData.defaultSkin, true); });
以上就是CocosCreator骨骼動畫之龍骨DragonBones的詳細內容,更多關於CocosCreator骨骼DragonBones的資料請關註WalkonNet其它相關文章!
推薦閱讀:
- None Found