Thagomizer lets you import animations from DragonBones Pro into DragonRuby and integrate them into your game without much code. DragonBones is a free, open source program program that lets you import PNG files and animate them.
This project is a work in progress.
Includes:
- simple skeletal animation composed of multiple sprites
- a single call each frame to update position/flip/scale and prepare the sprites to render
- built-in support for play/pause, stepping, and animation cycling
- optional debug overlays that reveal bone transforms and hitboxes
- simple hit testing using DragonRuby's geometry helpers
The name
thagomizerrefers to the four bone-like protrusions sometimes found at the end of dragon's tails. It is more commonly found on stegosaurus tails. The name was invented by Gary Larson.
- Animate position, rotation and scale
- Switch between multiple animations within the same file
- Linear tweening
- Basic hit detection
- Visual debugging layer
Potential future features include:
- Better tweening
- Change animation playback rate
- Single-run animations which let you know when they're done
- Inverse Kinematics
- Option for more accurate/less performant/more labour intensive hit detection
- Mesh deformation (DragonRuby Indie or Pro licence required because triangles)
- Support for other skeletal animation software such as Spine
Copy the app/thagomizer.rb file into your DragonRuby project. Require it from your app/main.rb file (or wherever suits you best).
require 'app/thagomizer'To export your animations from DragonBones Pro:
- Go to File > Export...
- In the
Animation Data + Texture tabsetType: DragonBones JSON - Set the
Output Pathto create a new folder using only lowercase letters or underscores, e.g.myproject - If necessary, change the project name to use only lowercase letters or underscores
- Ensure that
Generated Filesincludes bothDataandTexture - Locate the exported folder and verify that it contains 3 files:
myproject_ske.jsonmyproject_tex.jsonmyproject_tex.png - Move the folder (or the files if you prefer) to your DragonRuby project. A fine location would be:
app/sprites/myproject
# create once
character = Thagomizer.new(
args,
'sprites/myproject/projectname_ske.json',
'sprites/myproject/myproject_tex.json',
'sprites/myproject/myproject_tex.png',
scale: 1
)
# each tick
args.outputs.primitives << character.animate(args)The animate method has a number of optional arguments that you can use to position, scale and flip the animation:
def animate(args, x: @origin.x, y: @origin.y, scale: @scale, flipped: @flipped)Parameters:
animate(args)alone will advance the animationx/y: override the current origin (defaults to the previous position)scale: optional scale factor (defaults to the previous value)flipped: set totrueto mirror the animation horizontally
Returns:
- the method returns primitives for the current frame of the animation
Thagomizer.new(args, skeleton_path, texture_json_path, texture_png_path, scale: 1.0, x: nil, y: nil)scale/x/y– optional initial transform
animate(args, x:, y:, scale:, flipped:)→ returns array of sprite primitives
play("name")– switch to a different animation in the same fileflipped=- mirror the animation so it faces the opposite directionflipped?- checks if the animation is currently flippedplaying_animation– returns the current animation name
hit_test(point_or_rect)– returns the topmost sprite whose AABB intersects the passed point or rect
Toggle debug with % (Shift-5). While active:
- Arrow keys – pan
=/-– scaleEsc– reset pan/scalep– play/pause,/.– frame stepn– next animationb– toggle bone displayl– toggle bone labels (only visible if bones are visible)s– toggle sprite bounds display (rotated sprite boundary)h– toggle hitbox displayi– toggle debug info[/]– select previous/next bone/– toggle display of non-selected sprites
The overlay shows axes, bones, sprite bounds, and hitboxes. Hovering a hitbox highlights it so you can see which sprite the point intersects. debug_watches includes frame/animation info and, when enabled, the selected bone’s world/local transforms.
- Hitboxes are simple AABBs aligned to the sprite’s current orientation.
argsis refreshed every frame insideanimate/tickso this lib should be compatible with testing- If
x/yare not provided to the constructor, the animation's origin will be the center of the window
This library: MIT License Dragon animation and images from https://github.com/DragonBones: MIT License