Thanks to visit codestin.com
Credit goes to github.com

Skip to content

oeloeloel/thagomizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thagomizer

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 thagomizer refers 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.

Supports

  • Animate position, rotation and scale
  • Switch between multiple animations within the same file
  • Linear tweening
  • Basic hit detection
  • Visual debugging layer

Room for improvement

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

Installation

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'

Animation Files

To export your animations from DragonBones Pro:

  1. Go to File > Export...
  2. In the Animation Data + Texture tab set Type: DragonBones JSON
  3. Set the Output Path to create a new folder using only lowercase letters or underscores, e.g. myproject
  4. If necessary, change the project name to use only lowercase letters or underscores
  5. Ensure that Generated Files includes both Data and Texture
  6. Locate the exported folder and verify that it contains 3 files: myproject_ske.json myproject_tex.json myproject_tex.png
  7. Move the folder (or the files if you prefer) to your DragonRuby project. A fine location would be: app/sprites/myproject

Quick Start

# 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 animation
  • x / y: override the current origin (defaults to the previous position)
  • scale: optional scale factor (defaults to the previous value)
  • flipped: set to true to mirror the animation horizontally

Returns:

  • the method returns primitives for the current frame of the animation

Constructor

Thagomizer.new(args, skeleton_path, texture_json_path, texture_png_path, scale: 1.0, x: nil, y: nil)
  • scale / x / y – optional initial transform

Per-frame

  • animate(args, x:, y:, scale:, flipped:) → returns array of sprite primitives

Playback & transform

  • play("name") – switch to a different animation in the same file
  • flipped= - mirror the animation so it faces the opposite direction
  • flipped? - checks if the animation is currently flipped
  • playing_animation – returns the current animation name

Hitboxes

  • hit_test(point_or_rect) – returns the topmost sprite whose AABB intersects the passed point or rect

Debug Shortcuts (when in debug mode)

Toggle debug with % (Shift-5). While active:

  • Arrow keys – pan
  • = / - – scale
  • Esc – reset pan/scale
  • p – play/pause
  • , / . – frame step
  • n – next animation
  • b – toggle bone display
  • l – toggle bone labels (only visible if bones are visible)
  • s – toggle sprite bounds display (rotated sprite boundary)
  • h – toggle hitbox display
  • i – toggle debug info
  • [ / ] – select previous/next bone
  • / – toggle display of non-selected sprites

Debug Overlay

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.

Notes

  • Hitboxes are simple AABBs aligned to the sprite’s current orientation.
  • args is refreshed every frame inside animate/tick so this lib should be compatible with testing
  • If x/y are not provided to the constructor, the animation's origin will be the center of the window

License

This library: MIT License Dragon animation and images from https://github.com/DragonBones: MIT License

About

DragonBones Player for DragonRuby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages