hi,
I'm using cocos2d-js runtime.
I have serveral characters , and a weapon texture atlas shared by the characters.I try to change a character's weapon by doing this:
var ske = this._skeleton;
sp._atlasLoader.setAtlasFile("res/weapon.atlas");
var atlas = new spine.Atlas(cc.loader.getRes("res/weapon.atlas") , sp._atlasLoader);
var attLoader = new spine.AtlasAttachmentLoader(atlas);
var at = attLoader.newRegionAttachment(newSkin , "weapon" , "weapon1");
var newSkin = new spine.Skin("newSkin");
var skin = ske.data.findSkin("default");
for(var k in skin.attachments){
var arr = k.split(":");
var index = parseInt(arr[0]);
var name = arr[1];
if(name == "weapon"){
newSkin.addAttachment(index , name , at);
}
else
newSkin.addAttachment(index , name , skin.attachments[k]);
}
ske.setSkin(newSkin);
ske.setToSetupPose();
It doesn't work. the weapon is missing, what i did something wrong?
Is there anybody show me a piece of example code? Thanks!
Resolved.
var map = jsonData["skins"]["skins01"][slotName][attachmentName];
map = utils.cloneJson(map);//deep clone
map.path = "wuqi0001";//sprite name in texturepacker atlas
var attachment = skeletonJsonReader.readAttachment(newSkin , null , map);
newSkin.addAttachment(index , slotName, attachment);