Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EaselJS Spritesheets from TexturePacker

How do you create proper spritesheet exports for EaselJS from TexturePacker? After exporting I get something like this ...

{
"images": ["textures.png"],
"frames": [
    [818, 44, 42, 42], 
    [818, 1, 42, 42], 
    [775, 87, 42, 42], 
    [775, 44, 42, 42], 
    [775, 1, 42, 42], 
    [732, 87, 42, 42], 
    [732, 44, 42, 42], 
    [732, 1, 42, 42], 
    [689, 87, 42, 42], 
    [689, 44, 42, 42]
],
"animations": {
        "load_indicator_01":[0], 
        "load_indicator_02":[1], 
        "load_indicator_03":[2], 
        "load_indicator_04":[3], 
        "load_indicator_05":[4], 
        "load_indicator_06":[5], 
        "load_indicator_07":[6], 
        "load_indicator_08":[7], 
        "load_indicator_09":[8], 
        "load_indicator_10":[9]
},
"texturepacker": [
        "SmartUpdateHash: $TexturePacker:SmartUpdate:9148c4d9cc1b277627212fb0bffcda4d:fabda013c371507b8fb93d52f15735a0:205920eec6ac5ad8b6794732cd49ae1d$",
        "Created with TexturePacker (http://www.texturepacker.com) for EaselJS"
]
}

Every frame is defined as an animation which is pointless. Is this exporter just a joke or how can I export for EaselJS properly? Any trick involved?

like image 795
BadmintonCat Avatar asked Dec 01 '25 03:12

BadmintonCat


2 Answers

basically its the format easeljs ask for a spritesheet you would do the next:

$.getJSON("sprites.json", function(json) {
    spriteSheet = new createjs.SpriteSheet(json);
});

and create a variable for each frame, in your case:

var load_indicator_01 = new createjs.Sprite(spriteSheet, "load_indicator_01");

to automate i made this snippet:

var spriteSheet;
var sprites = {}
$.getJSON("sprites.json", function(json) {
    spriteSheet = new createjs.SpriteSheet(json);
    for(var sprite in json.animations){
        sprites[sprite] = new createjs.Sprite(spriteSheet, sprite);
    }
});

`

like image 190
Felipe Méndez Avatar answered Dec 02 '25 19:12

Felipe Méndez


TexturePacker is capable of generating a .json file with the correct "animations" object to pass to the EaselJS SpriteSheet constructor. In your example, it would look like this:

"animations": {
  "load_indicator": { "frames": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
},

However, two things need to be true in order for the correct .json information to be auto-generated.

  • Your image sequence files must have a hyphen - or underscore _ right before the frame numbering (e.g. "load_indicator_00.png" but not "load_indicator00.png").
  • You must have "Auto-detect animations" checked in the TexturePacker settings.
like image 39
fuzzy marmot Avatar answered Dec 02 '25 17:12

fuzzy marmot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!