Cocos Creator Dynamic loading dragonbones skeletal animation

Source: Internet
Author: User

First look at the Cocoscreator engineering structure, as shown below:



The goal is to click the button in the upper right corner to add a dragon animation to Actorlayer, the code is as follows:



Cc. Class ({extends:cc. Component, properties: {},//Use the For Initialization onload:function () {},/
    
    /called every frame, uncomment this function to activate update callback//update:function (DT) {//},
        Onclick_add:function () {var = this;
            Cc.loader.loadResAll (' Dragon ', function (err, assets) {if (err) {return;
            } if (assets.length <= 0) {return; } var Newhero = new CC.
            Node ();
            Self.node.addChild (Newhero);
            Newhero.setposition (CC.P (0,0));
            Newhero.setscale (0.5, 0.5);
            
            var dragondisplay = newhero.addcomponent (Dragonbones.armaturedisplay); for (var i in assets) {if (Assets[i] instanceof dragonbones.dragonbonesasset) {Dragondis
                Play.dragonasset = Assets[i];
         }       if (Assets[i] instanceof dragonbones.dragonbonesatlasasset) {dragondisplay.dragonatlasasset = a
                Ssets[i];
            }} dragondisplay.armaturename = ' Dragon ';
        Dragondisplay.playanimation (' stand ');
 })
    }
});



Note the point:

The Dragonasset property and the Dragonatlasasset property of the 1.dragonbones.armaturedisplay must be assigned a value loadres the object to which it is loaded;

2. Using CC.LOADER.LOADRESALL to dynamically load resources, the loaded resource must be placed under the resources directory;


Reference:

http://forum.cocos.com/t/topic/41362


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.