DBSprite: DragonBones support for Starling Builder

Starling Builder supports loading DragonBones animation through a custom component called DBSprite. The following document explains how to setup both editor and game.

For editor

  • Upgrade to the latest version of the editor.
  • Copy the latest EmbeddedComponents.swf to workspace/libs/
  • Open workspace/settings/ui_builder.json, set assetMediator to com.sgn.uicomponents.animation.DBAssetMediator
  • Click on Workspace → delete template override and reload the editor
  • Under container tab, you can see starlingbuilder.extensions.animation.DBSprite.
  • Export your atlas and skeleton data to xml format. Make sure both texture and animation files have the same name, e.g. dragon.png(image), dragon.xml(atlas), dragon.dat(skeleton data) and put them into any asset paths.
  • Click on DBSprite, fill in armature name, animation name and check autoPlay, you will see the animation play instantly inside the editor.

You can check out dragonbones_test.json in the latest demo workspace, which is already set up to work

For game

There are 2 dependencies you need to inject to DragonBones in order to make it work: StarlingFactory and WorldClock. Thanks to the IAssetMediator.getCustomData interface, you can inject basically everything you want into a custom component that takes a IAssetMediator as a constructor parameter.

In this case, this is what you need to do to implement the method

override public function getCustomData(type:String, name:String):Object
    switch (type)
        case DBSprite.STARLING_FACTORY:
            return _starlingFactory;
        case DBSprite.WORLD_CLOCK:
            return _worldClock;
            return null;

It’s up to you how to create and manage _starlingFactory and _worldClock in your game. As long as you return the right dependencies from IAssetMediator.getCustomData, it will work.

  builder/dbsprite.txt · Last modified: 2016/07/30 01:40 by johannh
Powered by DokuWiki