fix: texture-packer should include format of image file in spritesheet json file's name #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes it so that
texture-packer
includes the image format of the underlying spritesheet within the file name of the spritesheet's json file.For example, if it would previously output
[email protected]
, it now outputs[email protected]
Rationale
Including the underlying image format as part of a json spritesheet's filename appears to be required by convention in Pixi's spritesheet loader (link to Pixi.js documentation).
I ran into an issue where I was generating spritesheets with 3 different resolutions (e.g.
@1x
,@2x
,@3x
) but when loading them into Pixi, all resolutions would be ignored and the first spritesheet in the list (regardless of what resolution it was) would be loaded.After debugging the execution of both the Pixi loader and AssetPack, I determined the source of the problem: Pixi's loader does not attempt to parse the file names a spritesheet to extract metadata such as resolution if the spritesheet JSON file's filename does not adhere to the following filename convention:
my-spritesheet{resolution}.{imageFormat}.json
Solution
I changed AssetPack's
texture-packer
to include the underlying texture file format in the spritesheet JSON file's filename.I cannot see a reason why it should not be there, and I think the lack of it was by accidental omission rather than intentional. As it currently stands, spritesheets generated with AssetPack cannot be loaded correctly by Pixi when they contain multiple resolutions.
@Zyie please consider merging this PR or let me know how I could improve it.