pixi-tileset-loader
v1.0.0
Published
Webpack loader for generating tilesets for PIXI.js
Downloads
2
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
.tileset
inYAML
format
skip: 1
colors: 16
scale: 0.5
- Add
pixi-tileset-loader
inwebpack.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'
// }
}
}
]
}
import
orrequire
the.tileset
file 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 file
Processing
- 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/images
directory (specified byquery.output
) - Build PNG and JSON files in
example/output
directory intodist
(specified byoutput.path
in webpack config) by url-loader. This will replacemeta.image
in JSON withpath
orbase64
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.png
System dependencies
First to ensure these packages installed in system:
- ImageMagick:
identify
andconvert
command are required to get image information and resize image - pngquant:
pngquant
command 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.file
by default to generate JSON file;inline
to generate JSON module source code;none
to do nothingoptions.process
: to process frames or not. It will directly read JSON and PNG cache from the directory whereoutput
option specified to perform the build whenfalse
options.cacheable
: cache process result or not.false
by default,true
to read image and JSON files fromoptions.output
directory which are built already, if source image files andtileset
file are not changedoptions.name
: url-loadername
option for image and JSON filesoptions.outputPath
: url-loaderoutputPath
option for image and JSON filesoptions.publicPath
: url-loaderpublicPath
option 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.mode
specified asinline
options.verbose
: log the entire error stack or not, default isfalse
The option specified in
options
will be overwrite by the same option specified inoptions.image
oroptions.json
. Whenoptions.process
is specifiedfalse
, the 1 - 4 steps of processing will be skipped, PNG and JSON cache will be directly read from the directoryquery.output
specified, 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.cacheable
astrue
to 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.resource
can be specified'window.baseRoot + "$url"'
for example,baseRoot
is 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 isfalse
scale
: scale factor, based on imagemagick-stream to reduce the size of PNG image, default is1
padding
: padding in the spritesheet, default is10
skip
:ignore N frames in every N + 1 frames, default is0
colors
:colors amount for pngquant, default is0
files
: file paths in[path]-[name]
format, frames will be read from the directoryfiles
specified instead of the directory where.tileset
is inexcludes
: the file paths to excludeinterpolate
: string template to specify the prefix, such as$name$-tileset
andtileset
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