Parse sprite sheet image using object
See original GitHub issueLoading 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:
- Created 7 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

good shout @shshaw ! I think separating the parsers from the loaders is something we should look into!
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?