DragonBonesJS Documentation
repository·master·Indexed 19 days ago
https://github.com/dragonbones/dragonbonesjsA 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.
What's inside DragonBonesJS
- 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.
Supported Game Engines for DragonBones
masterDragonBones provides runtimes and integration guides for several major game engines. Use the following links to find specific implementation guides:
- Egret
- PixiJS
- Phaser
- Hilo
- Cocos Creator
Understand DragonBones 5.0 Data Format Changes
masterDragonBones 5.0 introduces several breaking changes and new features compared to version 4.5. Key changes include:
- Root Level: Added
compatibleVersion(minimum compatible version). RemovedisGlobal; absolute coordinates are no longer supported, only relative coordinates are used. - Display: The
nameproperty is now a unique identifier for the display item rather than a path. A newpathproperty is used to specify the texture path, mesh texture path, or sub-skeleton name. - Bounding Boxes: A new display type
boundingBoxis supported. It includes asubType(rectangle,ellipse, orpolygon) and specific properties likewidth,height, orverticesdepending on the type. - Linked Mesh: Mesh-type displays can now use a
shareproperty to become a shared mesh. UseinheritFFDto control whether the shared mesh inherits the FFD (Free-Form Deformation) animation from the master mesh. - Z-Order Animation: A new
zOrderproperty in animations allows for depth sorting on a timeline via aframesarray containingdurationand azOrderarray of slot changes. - Unified Events: Events are now thrown from the main animation timeline instead of individual bone timelines. The
eventproperty in frames is renamed toevents(an array). - Tweening: Frames now include a
tweenTypeproperty. A value of0uses standardtweenEasingorcurve, while non-zero values are reserved for future extended easing types.
- Root Level: Added
View DragonBones Phaser Demos
masterYou can explore implementation examples in the Demos directory, including theHello DragonBonesexample located atDemos/src/HelloDragonBones.ts.Configure project structure for Hilo
masterWhen integrating Hilo into your project, ensure your directory structure includes the
hilo.d.tsdeclaration file within alibsfolder to support TypeScript definitions.Your project |-- libs |-- hilo.d.ts |-- node_modules |-- ... |-- out |-- ... |-- src |-- ... |-- ...Generate engine-specific DragonBones dependency files
masterYou can use the
dragonbones-runtimeCLI 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:
- Install the CLI globally via npm:
npm install -g dragonbones-runtime - Run the
dbrcommand specifying the engine and version. - The generated files will be placed in a
dragonbones-outdirectory 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.2ordbr phaser-ce@2.7.0 - Hilo:
dbr hilo@1.1.6
npm install -g dragonbones-runtime dbr egret@4.1.0- Install the CLI globally via npm:
Integrate DragonBones with Phaser
masterTo use DragonBones in a Phaser project, you must register the
DragonBonesPluginwithin yourPhaser.Gameconfiguration object. Ensure thestartproperty is set totrueto initialize the plugin automatically.const gameConfig = { plugins: { global: [ { key: "DragonBonesPlugin", plugin: dragonBones.phaser.plugin.DragonBonesPlugin, start: true } ] }, scene: TestSceneToDisplay }; new Phaser.Game(gameConfig);Get Hilo TypeScript declarations
masterTo use Hilo with TypeScript, you must include the
hilo.d.tsdeclaration file in your project. You can obtain the latest definitions from the Hilo team's repository.https://github.com/hiloteam/Hilo/tree/dev/d.tsExplore DragonBones ThreeJS demos
masterTo see how DragonBones integrates with ThreeJS, you can view the available demos. The primary entry point for a basic implementation is the
HelloDragonBonesdemo, which demonstrates the core setup and animation playback within a ThreeJS environment./* View the Hello DragonBones implementation at: */ // ./Demos/src/HelloDragonBones.tsSet up demo resources for PixiJS demos
masterTo run the PixiJS 8.x demos, you must manually copy the assets and materials located in the
Demos/resourcefolder 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/Run the Hilo demos
masterTo run the Hilo demonstration project, install the dependencies using npm and then start the development server with the start command.
$ npm install $ npm run startObtain PixiJS dependencies
masterFor the PixiJS integration, you will need to acquire the following files:
- pixi.js: Download the release from the official PixiJS releases.
- pixi.js.d.ts: For TypeScript support, download the type definitions from the PixiJS TypeScript repository.