DragonBonesJS Documentation

repository·master·Indexed 19 days ago

https://github.com/dragonbones/dragonbonesjs

A runtime library for playing skeletal animations in JavaScript and TypeScript environments. It serves as the playback engine for animations created in tools like LoongBones and provides integration packages for various web-based game engines, including Cocos Creator 1.x, Egret 4.x, Hilo 1.x, and Phaser 2.x/3.x.

Tokens
14.7K
Snippets
48
Records
79
Agent score
73%

What's inside DragonBonesJS

  1. Overview of DragonBones JavaScript / TypeScript Runtime

    master
    DragonBones is a JavaScript/TypeScript runtime for playing skeletal animations. It provides a common library for animation data and specific integration packages for various game engines. For creating the animation assets themselves, it is highly recommended to use LoongBones.
  2. Understand DragonBones 5.0 Data Format Changes

    master

    DragonBones 5.0 introduces several breaking changes and new features compared to version 4.5. Key changes include:

    • Root Level: Added compatibleVersion (minimum compatible version). Removed isGlobal; absolute coordinates are no longer supported, only relative coordinates are used.
    • Display: The name property is now a unique identifier for the display item rather than a path. A new path property is used to specify the texture path, mesh texture path, or sub-skeleton name.
    • Bounding Boxes: A new display type boundingBox is supported. It includes a subType (rectangle, ellipse, or polygon) and specific properties like width, height, or vertices depending on the type.
    • Linked Mesh: Mesh-type displays can now use a share property to become a shared mesh. Use inheritFFD to control whether the shared mesh inherits the FFD (Free-Form Deformation) animation from the master mesh.
    • Z-Order Animation: A new zOrder property in animations allows for depth sorting on a timeline via a frames array containing duration and a zOrder array of slot changes.
    • Unified Events: Events are now thrown from the main animation timeline instead of individual bone timelines. The event property in frames is renamed to events (an array).
    • Tweening: Frames now include a tweenType property. A value of 0 uses standard tweenEasing or curve, while non-zero values are reserved for future extended easing types.
  3. Configure project structure for Hilo

    master

    When integrating Hilo into your project, ensure your directory structure includes the hilo.d.ts declaration file within a libs folder to support TypeScript definitions.

    Your project
        |-- libs
            |-- hilo.d.ts
        |-- node_modules
            |-- ...
        |-- out
            |-- ...
        |-- src
            |-- ...
        |-- ...
  4. Generate engine-specific DragonBones dependency files

    master

    You can use the dragonbones-runtime CLI tool to generate the necessary DragonBones files (.js, .d.ts) required for specific game engines. This is useful for integrating DragonBones into your project's build pipeline.

    Steps:

    1. Install the CLI globally via npm: npm install -g dragonbones-runtime
    2. Run the dbr command specifying the engine and version.
    3. The generated files will be placed in a dragonbones-out directory in your current working directory (unless specified otherwise).

    Supported Engines and Examples:

    • Egret: dbr egret@4.1.0
    • PixiJS: dbr pixijs@4.6.2
    • Phaser: dbr phaser@2.6.2 or dbr phaser-ce@2.7.0
    • Hilo: dbr hilo@1.1.6
    npm install -g dragonbones-runtime
    dbr egret@4.1.0
  5. Integrate DragonBones with Phaser

    master

    To use DragonBones in a Phaser project, you must register the DragonBonesPlugin within your Phaser.Game configuration object. Ensure the start property is set to true to initialize the plugin automatically.

    const gameConfig = {
        plugins: {
            global: [
                { key: "DragonBonesPlugin", plugin: dragonBones.phaser.plugin.DragonBonesPlugin, start: true }
            ]
        },
        scene: TestSceneToDisplay
    };
    
    new Phaser.Game(gameConfig);
  6. Explore DragonBones ThreeJS demos

    master

    To see how DragonBones integrates with ThreeJS, you can view the available demos. The primary entry point for a basic implementation is the HelloDragonBones demo, which demonstrates the core setup and animation playback within a ThreeJS environment.

    /* View the Hello DragonBones implementation at: */
    // ./Demos/src/HelloDragonBones.ts
  7. Set up demo resources for PixiJS demos

    master

    To run the PixiJS 8.x demos, you must manually copy the assets and materials located in the Demos/resource folder of the repository into your local project's resource directory. These materials are required for the animations and assets to load correctly during the demo execution.

    # Example command to copy resources (adjust paths as necessary)
    cp -r ../../resource/* ./resource/