@theatrejs/loader-aseprite
Version:
⚙️ A Webpack Loader for Aseprite files.
125 lines (105 loc) • 4.08 kB
Markdown
[](https://github.com/deformhead) [](https://github.com/theatrejs/loader-aseprite/blob/master/LICENSE) [](https://www.npmjs.com/package/@theatrejs/loader-aseprite/v/latest) [](https://www.npmjs.com/package/@theatrejs/loader-aseprite/v/latest)
# Aseprite Webpack Loader
> *⚙️ A Webpack Loader for Aseprite files.*
## Installation
> *⚠️ This loader needs you to have [**Aseprite**](https://www.aseprite.org) installed.*
```shell
npm install /plugin-aseprite --save
```
```shell
npm install /loader-aseprite --save-dev
```
## Webpack Configuration
```javascript
{
'module': {
'rules': [
...
{
'test': /\.aseprite$/,
'use': [
{
'loader': '@theatrejs/loader-aseprite',
'options': {
'aseprite': '<path-to-aseprite>' // The path to the Aseprite executable.
}
}
]
}
...
]
}
}
```
## Webpack Configuration (Advanced Options)
```javascript
{
'module': {
'rules': [
...
{
'test': /\.aseprite$/,
'use': [
{
'loader': '@theatrejs/loader-aseprite',
'options': {
'aseprite': '<path-to-aseprite>', // The path to the Aseprite executable.
'constants': true, // The option for generating the constants files with all the Aseprite animation tags.
'prepare': {
'sheet': 'packed', // The Aseprite output 'sheet type' option ('columns' | 'horizontal' | 'packed' | 'rows' | 'vertical') ('rows' by default).
'trim': true // The Aseprite output 'trim cels' option (false by default).
},
'processing': {
'colorswap': [
{
'source': [255, 0, 255, 255], // A source color to swap from (in rgba).
'target': [0, 0, 0, 0] // A target color to swap to (in rgba).
}
]
}
}
}
]
}
...
]
}
}
```
## Quick Start
> *⚠️ This example does not include the preloading of assets.*
```javascript
import {Stage} from '@theatrejs/theatrejs';
import * as PLUGIN_ASEPRITE from '@theatrejs/plugin-aseprite';
import * as ANIMATIONS_HERO from './hero-16x16.animations.js';
import asepriteHero from './hero-16x16.aseprite';
class Level1 extends Stage {
onCreate() {
this.createActor(
PLUGIN_ASEPRITE.FACTORIES.ActorWithSpritesheet({
$aseprite: asepriteHero,
$loop: true,
$tag: ANIMATIONS_HERO.IDLE
})
);
}
}
```
## With Preloading
```javascript
import {FACTORIES} from '@theatrejs/theatrejs';
import * as PLUGIN_ASEPRITE from '@theatrejs/plugin-aseprite';
import * as ANIMATIONS_HERO from './hero-16x16.animations.js';
import asepriteHero from './hero-16x16.aseprite';
class Level1 extends FACTORIES.StageWithPreloadables([PLUGIN_ASEPRITE.FACTORIES.PreloadableAseprite(asepriteHero)]) {
onCreate() {
this.createActor(
PLUGIN_ASEPRITE.FACTORIES.ActorWithSpritesheet({
$aseprite: asepriteHero,
$loop: true,
$tag: ANIMATIONS_HERO.IDLE
})
);
}
}
```