question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parse sprite sheet image using object

See original GitHub issue

Loading the JSON for a spritesheet loads the image and creates frames automatically, but when using something like Webpack, it would be great to save a roundtrip request and build the spritesheet json data into the bundle.

Unfortunately, there’s no easy way to use PIXI’s built in spritesheet parser to make frames from the data when the image is loaded. A built-in method along the lines of PIXI.utils.framesFromData( jsonData, image or Texture ) would be quite helpful!

@danielberndt built a method to do this, and I adapted it use the built in spritesheetParser middleware, but this is easily broken if spritesheetParser changes.

import PIXI from "pixi.js";

export default function loadFromJson(name, pathToImage, data, resolution = parseInt(data.meta.scale, 10)) {

  var loader = new PIXI.loaders.Loader();

  PIXI.loaders.spritesheetParser().call(loader, {
      name: name,
      url: pathToImage,
      data: data,
      isJson: true,
      metadata: {}
    }, function(){ console.log('next', arguments, PIXI.utils.TextureCache); });

  return loader;
}

Usage:

import loadFromJson from "./loadFromJson.js";

var loader = loadFromJson(
  'spritesheet', 
  require("../spritesheets/spritesheet.png"), 
  require("../spritesheets/spritesheet.json")
);

function onAssetsLoaded(){
  var body = new PIXI.Sprite.fromFrame('body.png');
}
loader.load(onAssetsLoaded);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
GoodBoyDigitalcommented, Sep 4, 2016

good shout @shshaw ! I think separating the parsers from the loaders is something we should look into!

1reaction
amorinocommented, Jan 12, 2017

The method from above doesn’t work anymore on 4.3.2 with webpack; and Pixi.js docs doesn’t have any reference to Pixi.loaders.spritesheetParser.

Is there any way to make this work for webpack?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parse sprite sheet image using object · Issue #2906 - GitHub
Unfortunately, there's no easy way to use PIXI's built in spritesheet parser to make frames from the data when the image is loaded....
Read more >
How to Load, Parse, and Use Sprite Sheets - YouTube
Pygame Sprite Sheet Tutorial: How to Load, Parse, and Use Sprite Sheets ... Code and images for this tutorial can be downloaded at: ......
Read more >
Using Sprite Sheets in Pygame - Python Crash Course, 2nd ...
To use a sprite sheet, you load the sprite sheet as a single large image, and then you load the individual images from...
Read more >
C# SpriteSheet Reader & Parser - CodeProject
This brief code is meant to read and parse a spritesheet coordinates file and extract its corresponding Image objects.
Read more >
How to extract sprites out from Sprite Sheet in SpriteKit?
I wanted to extract each of the sprites in the following sprite sheet. Provided with the key-value of sprite origin points in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found