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