pixi-tileset-loader
v1.0.0
Published
Webpack loader for generating tilesets for PIXI.js
Downloads
10
Maintainers
Readme
pixi-tileset-loader
Webpack loader for generating tilesets for PIXI.js
Install
npm install pixi-tileset-loader -D
Usage
- Add a
.tileset(or other filename) file in frames directory
animation
├── .tileset
├── 001.png
├── 002.png
└── 003.png- See Image processing params to configure
.tilesetinYAMLformat
skip: 1
colors: 16
scale: 0.5- Add
pixi-tileset-loaderinwebpack.config.js:
{
test: /\.tileset/i,
use: [
{
loader: 'pixi-tileset-loader',
options: {
process: true,
mode: 'file',
output: './output',
name: '[name]_[hash:6].[ext]',
limit: false,
outputPath: 'res'
output: 'game/images',
// image: {
// outputPath: 'res',
// publicPath: './'
// },
// json: {
// outputPath: 'res',
// publicPath: './res'
// }
}
}
]
}importorrequirethe.tilesetfile in your module
import tilesetAnimationJSON from './resources/animation/.tileset';
// Will get a JSON file path in return,and the image path will be replaced in JSON fileProcessing
- Read from cache to know weather images and tileset are change or not
- Spritesheet:genarate PNG and JSON files using spritesheet.js
- Image optimizing:use node-pngquant to reduce colors amount of PNG image
- Write the PNG and JSON files into
game/imagesdirectory (specified byquery.output) - Build PNG and JSON files in
example/outputdirectory intodist(specified byoutput.pathin webpack config) by url-loader. This will replacemeta.imagein JSON withpathorbase64
example
└── resources
│ ├── animation # where source images are stored
│ │ ├── .tileset
│ │ ├── 001.png
│ │ ├── 002.png
│ │ └── 003.png
│ └── index.js
├── output # where JSON and image file are stored after process
│ ├── tileset-animation.json
│ └── tileset-animation.png
└── dist # final built result
├── main.js
└── res
├── tileset-animation_1512a1.json
└── tileset-animation_eee48e.pngSystem dependencies
First to ensure these packages installed in system:
- ImageMagick:
identifyandconvertcommand are required to get image information and resize image - pngquant:
pngquantcommand is required to reduce colors of PNG image
Options
options.output: the directory to cache PNG and JSON file, we recommend specifying a source code directory and commit this directory as well. The cache will be disabled when not specifiedoptions.mode: how webpack will build tileset JSON.fileby default to generate JSON file;inlineto generate JSON module source code;noneto do nothingoptions.process: to process frames or not. It will directly read JSON and PNG cache from the directory whereoutputoption specified to perform the build whenfalseoptions.cacheable: cache process result or not.falseby default,trueto read image and JSON files fromoptions.outputdirectory which are built already, if source image files andtilesetfile are not changedoptions.name: url-loadernameoption for image and JSON filesoptions.outputPath: url-loaderoutputPathoption for image and JSON filesoptions.publicPath: url-loaderpublicPathoption for image and JSON filesoptions.image: url-loader webpack loader options for PNG fileoptions.json: url-loader webpack loader options for JSON file. Not required whenoptions.modespecified asinlineoptions.verbose: log the entire error stack or not, default isfalse
The option specified in
optionswill be overwrite by the same option specified inoptions.imageoroptions.json. Whenoptions.processis specifiedfalse, the 1 - 4 steps of processing will be skipped, PNG and JSON cache will be directly read from the directoryquery.outputspecified, and webpack will emit these files via url-loader , but a webpack warning will be emitted as well. This ensure the build in remote server, where ImageMagick or pngquant package is missing. We recommend to specifyoptions.cacheableastrueto improve webpack building performance, by skipping 2 - 4 steps of processing, and avoid unwanted image and json file change due to different system environment(e.g. different version ofImageMagick) when source images and tileset file are not changedoptions.resourcecan be specified'window.baseRoot + "$url"'for example,baseRootis a path similar to/path/to/image. Used to concat image path when code running in browser
Image processing params
trim:trim the whitespace in PNG image or not, default isfalsescale: scale factor, based on imagemagick-stream to reduce the size of PNG image, default is1padding: padding in the spritesheet, default is10skip:ignore N frames in every N + 1 frames, default is0colors:colors amount for pngquant, default is0files: file paths in[path]-[name]format, frames will be read from the directoryfilesspecified instead of the directory where.tilesetis inexcludes: the file paths to excludeinterpolate: string template to specify the prefix, such as$name$-tilesetandtileset
files specifies the paths relative to the directory where .tileset is in, for example:
files:
../animation-a/001.png: animation-a
../animation-b/001.png: animation-b
../animation-c/001.png: animation-c