Skip to content

Commit

Permalink
allow switching between loading by index and prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
MondayHopscotch committed Oct 17, 2023
1 parent 509ad2e commit 77e3ed8
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 62 deletions.
120 changes: 72 additions & 48 deletions Other/FlxAspriteUtils/assets/player.json
Original file line number Diff line number Diff line change
@@ -1,203 +1,227 @@
{ "frames": {
"player 0.ase": {
{ "frames": [
{
"filename": "idle:0",
"frame": { "x": 0, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 1.ase": {
{
"filename": "jump:1",
"frame": { "x": 80, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 2.ase": {
{
"filename": "fall:2",
"frame": { "x": 160, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 3.ase": {
{
"filename": "duck:3",
"frame": { "x": 240, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 4.ase": {
{
"filename": "fall:4",
"frame": { "x": 320, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 5.ase": {
"frame": { "x": 0, "y": 110, "w": 80, "h": 110 },
{
"filename": "climb:5",
"frame": { "x": 400, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 6.ase": {
"frame": { "x": 80, "y": 110, "w": 80, "h": 110 },
{
"filename": "climb:6",
"frame": { "x": 480, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 7.ase": {
"frame": { "x": 160, "y": 110, "w": 80, "h": 110 },
{
"filename": "cheer:7",
"frame": { "x": 560, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 8.ase": {
"frame": { "x": 240, "y": 110, "w": 80, "h": 110 },
{
"filename": "cheer:8",
"frame": { "x": 640, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 9.ase": {
"frame": { "x": 320, "y": 110, "w": 80, "h": 110 },
{
"filename": "walk:9",
"frame": { "x": 720, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 10.ase": {
"frame": { "x": 0, "y": 220, "w": 80, "h": 110 },
{
"filename": "walk:10",
"frame": { "x": 800, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 11.ase": {
"frame": { "x": 80, "y": 220, "w": 80, "h": 110 },
{
"filename": "hold:11",
"frame": { "x": 880, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 12.ase": {
"frame": { "x": 160, "y": 220, "w": 80, "h": 110 },
{
"filename": "hold:12",
"frame": { "x": 960, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 13.ase": {
"frame": { "x": 240, "y": 220, "w": 80, "h": 110 },
{
"filename": "action:13",
"frame": { "x": 1040, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 14.ase": {
"frame": { "x": 320, "y": 220, "w": 80, "h": 110 },
{
"filename": "action:14",
"frame": { "x": 1120, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 15.ase": {
"frame": { "x": 0, "y": 330, "w": 80, "h": 110 },
{
"filename": "kick:15",
"frame": { "x": 1200, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 16.ase": {
"frame": { "x": 80, "y": 330, "w": 80, "h": 110 },
{
"filename": "swim:16",
"frame": { "x": 1280, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 17.ase": {
"frame": { "x": 160, "y": 330, "w": 80, "h": 110 },
{
"filename": "swim:17",
"frame": { "x": 1360, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 18.ase": {
"frame": { "x": 240, "y": 330, "w": 80, "h": 110 },
{
"filename": "talk:18",
"frame": { "x": 1440, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 19.ase": {
"frame": { "x": 320, "y": 330, "w": 80, "h": 110 },
{
"filename": "slide:19",
"frame": { "x": 1520, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 20.ase": {
"frame": { "x": 0, "y": 440, "w": 80, "h": 110 },
{
"filename": "hang:20",
"frame": { "x": 1600, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 21.ase": {
"frame": { "x": 80, "y": 440, "w": 80, "h": 110 },
{
"filename": "skid:21",
"frame": { "x": 1680, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 22.ase": {
"frame": { "x": 160, "y": 440, "w": 80, "h": 110 },
{
"filename": "back:22",
"frame": { "x": 1760, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
},
"player 23.ase": {
"frame": { "x": 240, "y": 440, "w": 80, "h": 110 },
{
"filename": "stand:23",
"frame": { "x": 1840, "y": 0, "w": 80, "h": 110 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 80, "h": 110 },
"sourceSize": { "w": 80, "h": 110 },
"duration": 100
}
},
],
"meta": {
"app": "http://www.aseprite.org/",
"version": "1.3-rc6-x64",
"app": "https://www.aseprite.org/",
"version": "1.3-rc4-x64",
"image": "player.png",
"format": "RGBA8888",
"size": { "w": 400, "h": 550 },
"size": { "w": 1920, "h": 110 },
"scale": "1",
"frameTags": [
{ "name": "idle", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" },
Expand Down
Binary file modified Other/FlxAspriteUtils/assets/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 47 additions & 14 deletions Other/FlxAspriteUtils/source/PlayState.hx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package;

import flixel.animation.FlxAnimation;
import flixel.FlxG;
import flixel.ui.FlxButton;
import flixel.text.FlxText;
import flixel.graphics.FlxAsepriteUtil;
import flixel.FlxSprite;
import flixel.FlxState;

using flixel.util.FlxSpriteUtil;
import flixel.animation.FlxAnimation;
import flixel.graphics.FlxAsepriteUtil;
import flixel.text.FlxText;
import flixel.ui.FlxButton;

/**
* @author MondayHopscotch
Expand All @@ -18,6 +16,7 @@ class PlayState extends FlxState
static inline var POINTER_VERTICAL_OFFSET = 3;
static inline var ANIM_NAME_LINE_SPACING = 10;

var loadTitle:FlxText;
var loadedAnimations:FlxText;
var animList:Array<FlxAnimation>;
var currentAnimationLabel:FlxText;
Expand All @@ -26,44 +25,73 @@ class PlayState extends FlxState
var curAnimIndex = 0;
var pointer:FlxSprite;

var loadAtlasButton:FlxButton;
var nextButton:FlxButton;
var previousButton:FlxButton;

override public function create():Void
{
player = new FlxSprite();
FlxAsepriteUtil.loadAseAtlasAndTagsByIndex(player, "assets/player.png", "assets/player.json");
player.screenCenter();
add(player);

animList = player.animation.getAnimationList();
loadTitle = new FlxText();
add(loadTitle);

loadedAnimations = new FlxText(20);
loadedAnimations.text = animList.map((a) -> { a.name; }).join("\n");
loadedAnimations.screenCenter(Y);
add(loadedAnimations);

pointer = new FlxSprite("assets/pointer.png");
add(pointer);

currentAnimationLabel = new FlxText(player.animation.name);
currentAnimationLabel = new FlxText(0, 0, 0, player.animation.name);
currentAnimationLabel.alignment = CENTER;
currentAnimationLabel.y = FlxG.height - currentAnimationLabel.height;
add(currentAnimationLabel);

previousButton = new FlxButton("Previous", () -> {
previousButton = new FlxButton(0, 0, "Previous", () -> {
setPlayerAnim(curAnimIndex-1);
});
previousButton.setPosition(0, FlxG.height - previousButton.height);
add(previousButton);


nextButton = new FlxButton("Next", () -> {
nextButton = new FlxButton(0, 0, "Next", () -> {
setPlayerAnim(curAnimIndex+1);
});
nextButton.setPosition(FlxG.width - nextButton.width, FlxG.height - nextButton.height);
add(nextButton);

loadAtlasButton = new FlxButton(0, 0, "", () -> {
loadAnims(BY_PREFIX);
});
loadAtlasButton.setPosition(FlxG.width - loadAtlasButton.width, 0);
add(loadAtlasButton);

loadAnims(BY_INDEX);
}

function loadAnims(parseType:AseParseType) {
switch parseType {
case BY_INDEX:
loadTitle.text = "Anims by Index";
FlxAsepriteUtil.loadAseAtlasAndTagsByIndex(player, "assets/player.png", "assets/player.json");
loadAtlasButton.text = "Load by Prefix";
loadAtlasButton.onUp.callback = () -> loadAnims(BY_PREFIX);
case BY_PREFIX:
loadTitle.text = "Anims by Prefix";
FlxAsepriteUtil.loadAseAtlasAndTagsByPrefix(player, "assets/player.png", "assets/player.json");
loadAtlasButton.text = "Load by Index";
loadAtlasButton.onUp.callback = () -> loadAnims(BY_INDEX);
}

loadTitle.screenCenter(X);
player.screenCenter();

animList = player.animation.getAnimationList();

loadedAnimations.text = animList.map((a) -> { a.name; }).join("\n");
loadedAnimations.screenCenter(Y);

setPlayerAnim(0);
}

Expand All @@ -81,3 +109,8 @@ class PlayState extends FlxState
currentAnimationLabel.screenCenter(X);
}
}

enum AseParseType {
BY_INDEX;
BY_PREFIX;
}

0 comments on commit 77e3ed8

Please # to comment.