Giter Club home page Giter Club logo

animate-frames's Introduction

animate-frames

animate-frames is a workflow tool for converting sprite frames into a spritesheet and animate compatible metadata files.

Usage:
  animate-frames [--animation <key> <frame0.png> <frame1.png> ...] [--image <spritesheet.png>] [--metadata <target.json>] [--fps <int>] [--yaml]

Example:
animate-frames \
  --animation Idle idle_0000.png idle_0001.png idle_0002.png \
  --animation Walk walk_0000.png walk_0001.png walk_0002.png \
  --spritesheet sprite.png \
  --metadata sprite.yaml \
  --image "path/to/sprite.png" \
  [--fps 60] \ # default: 24fps
  [--yaml] # default is JSON

Workflow

This is an example workflow using Krita and animate to create sprites iteratively.

Krita

Krita is a professional level, digital painting program. It's also open source and works wonderfully with a wacom drawing tablet. Most importantly, it allows for drawing animation with onion skinning.

Here are the example stick figure animations -- walk and dance.

walk.kra

walk krita

dance.kra

dance krita

Generate individual animation frames

In order to represent the animation, each project file will render as frames with a postfix'ed number.

Don't forget to change the basename.

walk render

dance render

Now, there's a folder with all the frames.

frames

Notice that there are duplicates of frames. This is because each frame implictly attaches a unit of time. In this case, one frame lasts for 1/24th second.

Use animate-frames for spritesheet and metadata file

Removing frame duplication, composing a spritesheet, and inferring metadata is the core of what animate-frames does. What cannot be inferred are required as arguments.

Here's the script the find frames then generate the spritesheet and metadata files.

compile-frames.sh

#! /bin/sh

match() {
	echo `find ./ -name "$1" -print0 | xargs -0 ls`
}

walk=$(match "walk_*.png")
dance=$(match "dance_*.png")

animate-frames \
	--spritesheet figure.png \
	--image "data/figure.png" \
	--metadata figure.yaml \
	--animation Walk $walk \
	--animation Dance $dance \
	--yaml \ # JSON is default
	--fps 24

Generated files

A clip describes area of each frame on the spritesheet. An animation is defined by a list of the clip indices and delays (in seconds).

figure.yaml

image: "data/figure.png"
alpha: null
clips:
- [0, 0, 91, 135, 58, 80] # 0
- [91, 0, 87, 135, 52, 78] # 1
- [178, 0, 86, 134, 53, 76] # 2
- [264, 0, 96, 131, 69, 75] # 3
- [0, 135, 77, 135, 60, 78] # 4
- [77, 135, 79, 131, 66, 74] # 5
- [156, 135, 79, 130, 67, 74] # 6
- [235, 135, 86, 132, 60, 75] # 7
- [0, 270, 44, 143, 26, 86] # 8
- [44, 270, 40, 139, 19, 81] # 9
- [84, 270, 61, 141, 38, 83] # 10
- [145, 270, 71, 137, 41, 81] # 11
- [216, 270, 53, 139, 29, 84] # 12
- [269, 270, 44, 137, 27, 83] # 13
- [0, 413, 61, 139, 37, 83] # 14
- [61, 413, 63, 141, 35, 84] # 15
animations:
  "Dance":
  - [0, 0.2083]
  - [1, 0.2083]
  - [2, 0.2083]
  - [3, 0.2083]
  - [4, 0.2083]
  - [5, 0.2083]
  - [6, 0.2083]
  - [7, 0.2083]
  "Walk":
  - [8, 0.2083]
  - [9, 0.2083]
  - [10, 0.2083]
  - [11, 0.2083]
  - [12, 0.2083]
  - [13, 0.2083]
  - [14, 0.2083]
  - [15, 0.2083]

All the frames are collapsed into one spritesheet.

figure.png

figure.png

Preview animation

Use animate-preview to preview the generated spritesheet and metadata files.

animate-preview --target figure.yaml --image figure.png --high-dpi --watch

animate preview

Build into game

When building a game, you'll want to use the animate and animate-sdl2 libraries to load and draw the sprites. The animate has functions to load the generated files.

animate-frames's People

Contributors

jxv avatar

Stargazers

 avatar 研究社交 avatar Alena Yampolskaya avatar  avatar Claudia Doppioslash avatar Tatsuya Hirose avatar Schell Carl Scivally avatar Mikolaj Konarski avatar Rehno Lindeque avatar Sandy Maguire avatar Brian McKenna avatar Pavel Krajcevski avatar Tung Dao avatar Kasper Dissing Bargsteen avatar  avatar Jonathan Fischoff avatar Simon Voordouw avatar Daniel Kahlenberg avatar

Watchers

James Cloos avatar  avatar

animate-frames's Issues

Bug: Maintain order of frames

Currently, there's a bug likely caused by foldr usage. The order of frames are reversed. Replace foldr with foldl' for clarity.

Remove duplicate images sooner

  • parallel image loading
  • After loading an image, create a hash based on the image data.
  • Create an ID or indirection to represent the image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.