Jump to content

Using PIXI.js Loader on a JSON with base64 encoded image leads to empty Resource.spritesheet.animations property


komali2
 Share

Recommended Posts

I have the following JSON output of a spritesheet building tool:

 

{
    "frames": {
        "Charge0.png": {
            "frame": {
                "x": 0,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "sourceSize": {
                "w": 32,
                "h": 32
            }
        },
        "Charge1.png": {
            "frame": {
                "x": 32,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "sourceSize": {
                "w": 32,
                "h": 32
            }
        },
        "Charge2.png": {
            "frame": {
                "x": 64,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "sourceSize": {
                "w": 32,
                "h": 32
            }
        },
        "Charge3.png": {
            "frame": {
                "x": 96,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 32,
                "h": 32
            },
            "sourceSize": {
                "w": 32,
                "h": 32
            }
        }
    },
    "meta": {
        "app": "https://github.com/piskelapp/piskel/",
        "version": "1.0",
        "image": "data:image/png;base64,iVBORw....(etc)",
        "format": "RGBA8888",
        "size": {
            "w": 128,
            "h": 32
        }
    }
}

I have the following code to load it:

 

    PIXI.Loader.shared
      .add('playerCharge', './assets/player-charge.json')
      .load((loader, resources) => {
        console.log(resources);
        //const animation = new PIXI.AnimatedSprite(resources.playerCharge.spritesheet.animations['image_sequence']);
        //console.log(animation);
      });
  }

According to the PIXIJS docs (which unfortunately don't give an example of what a valid JSON file should look like) https://pixijs.download/dev/docs/PIXI.AnimatedSprite.html , the resources instance (playerCharge) should have a spritesheet.animations property with some sort of named property in it. It does not. The animations object is empty. Therefore, I can't pass anything to AnimatedSprite.

 

What's the right way to use this? Seems the only way is to manually iterate through the spritesheet.textures object, which is, strangely, populated.

Link to comment
Share on other sites

There's no defined animations in that json. They have to be defined in TexturePacker itself.


If you cant define it in editor, or you dont find what is json format for them, you have to use the code from pixijs example to convertt textures for animation.

 

https://pixijs.download/dev/docs/packages_spritesheet_src_Spritesheet.js.html#line260

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...