DragonBones / DragonBonesJS

DragonBones TypeScript / JavaScript Runtime
MIT License
746 stars 321 forks source link

how to replace dragonBones`skin ( Instead of replacing slots individually, it replaces the current avatar skin as a whole)in phaser3 #130

Closed akeboshi1 closed 4 years ago

akeboshi1 commented 4 years ago

How to dynamically generate a png atlas that meets the current keel bones and position inside the phaser, and then replace the current avatar skin? Instead of replacing slots individually, it replaces the current avatar skin as a whole

jcyuan commented 4 years ago

1, how to generate atlas: you can just use the current atlas info to draw things onto the RenderTexture, actually this is a problem Phaser usage related. 2, for replacing whole skin:

   // 1 release old data
    this.textures.remove(oldTexKey);
    this.dragonbone.factory.removeTextureAtlasData('skins', true);
    this.dragonbone.factory.removeDragonBonesData('skins', true);

    // assume that you assets are loaded
    const skinDb = this.dragonbone.factory.parseDragonBonesData(this.cache.binary.get('heroSkinSkeleton'), 'skins', 1);
    skinDb.name = 'skins';  // reset name

    const tex = this.textures.get(newTexKey);
    const json = this.cache.json.get(newJsonKey);
    this.dragonbone.factory.parseTextureAtlasData(json, tex, 'skins', 1);
    this.cache.json.remove(newJsonKey);

    const data = this.dragonbone.factory.getArmatureData('hero', 'skins');
    this.dragonbone.factory.replaceSkin(this._hero.display.armature, data.defaultSkin, true);

any question feel free to reopen.