goldfire / phaser-webpack-loader

Asset loader for Phaser + Webpack.
MIT License
90 stars 4 forks source link

Loading TexturePacker sprite atlas #6

Closed joseasv closed 6 years ago

joseasv commented 6 years ago

I can't seem to load a sprite atlas created by TexturePacker using JSON(Hash) data format with the Trim sprite names option activated. I choose this format because is the most similar to the texture atlas found in the phaser-boilerplate demo (https://github.com/goldfire/phaser-boilerplate/blob/master/src/assets/sprites/textures.json).

Following the phaser-boilerplate demo I have mi atlas.png and atlas.json files in the assets/sprites folder and the string "atlas.png" in the sprites array of the AssetManifest object.

The errors I get are: Phaser.AnimationParser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object ./dist/95cfb517fde6e8c353c4115beda802af.json

And in my webpack file I have the rules: rules: [ ..., { test: /\.json$/, use: 'file-loader', }, ... ]

I can get to load images just fine.

joseasv commented 6 years ago

Ok, reading through the code I made the following fixes:

const AssetManifest = {
  images: [
    ...,
    'atlas.png'
  ],
  sprites: [
    'atlas.json',
  ]
};
export default AssetManifest;

Now I can load sprite atlases made with TexturePack.

goldfire commented 6 years ago

It looks like your file-loader config may have been wrong. We use file-loader with TexturePacker atlas files with no issues:

{
  test: /\.(png|jpg|gif|ico|svg|pvr|pkm|wav|mp3|webm)$/,
  use: ['file-loader?name=assets/[name].[ext]?[hash]'],
},
joseasv commented 6 years ago

You are right. Using the rule you posted along file-loader solves everything. Thanks and sorry for bothering you.

goldfire commented 6 years ago

No problem! I should probably update the readme to make it more clear.