Class SheetImport
Imports a character drawn in Aseprite (or any
tool that writes its sheet format, such as LibreSprite or TexturePacker's
"JSON (Array)") as a SpriteSheet and an ActorAnimator, so hand-drawn
art drops into a PlatformArt without any code per animation.
Export with File > Export Sprite Sheet: any layout, trim off, and
JSON Data with tags. Name each tag after the state it animates --
idle, walk, run, jump, fall, crouch, crawl, climb, wall,
dash, glide, jetpack, swim, grip, push, hurt or dead
(the MovementState names work too). Frame durations become the clip's
speed; a tag set to ping-pong plays forwards then back; jump, hurt
and dead play once, everything else loops. States with no tag fall back
as ActorAnimator always does (run to walk, fall to jump, ...).
import com.codename1.gaming.platformer.view.*;
import com.codename1.io.Util;
Image sheetImage = Image.createImage(Display.getInstance().getResourceAsStream(null, "/hero.png"));
String jsonText = Util.readToString(Display.getInstance().getResourceAsStream(null, "/hero.json"));
SheetImport hero = SheetImport.read(sheetImage, jsonText);
// a PlatformArt then answers sheet(actor) with hero.getSheet()
// and animator(actor) with hero.getAnimator()
-
Method Summary
Modifier and TypeMethodDescriptionThe animator, with a clip for every tag that names a state.getClips()Every clip by tag name, including tags that are not states.getSheet()The sheet, cut into frames.static SheetImportReads a sheet and its JSON.static MovementStateThe tag name's state, or null for a tag that is no state (an attack, a victory pose), which is still ingetClips().
-
Method Details
-
read
Reads a sheet and its JSON.
Parameters
image: the exported sheet imagejson: the exported JSON
Returns
the sheet, its animator and its clips by tag name
Throws
IllegalArgumentException: for a trimmed sheet, frames of different sizes, or JSON that is not a sprite sheet
-
stateFor
The tag name's state, or null for a tag that is no state (an attack, a victory pose), which is still in
getClips().Parameters
tag: a tag name
Returns
the state, or null
-
getSheet
The sheet, cut into frames.
Returns
the sheet
-
getAnimator
The animator, with a clip for every tag that names a state.
Returns
the animator
-
getClips
Every clip by tag name, including tags that are not states.
Returns
the live map
-