Skip to content

Add support for sprithesheets #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "phaser-webpack-loader",
"version": "2.0.0",
"author": "GoldFire Studios, Inc. (http://goldfirestudios.com)",
"description": "Asset loader for Phaser + Webpack.",
"author": "James Simpson <james@goldfirestudios.com> (http://goldfirestudios.com)",
"description": "Asset loader for Phaser + Webpack.",
"repository": {
"type": "git",
"url": "git://github.com/goldfire/phaser-webpack-loader.git"
Expand Down
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class WebpackLoader extends Phaser.Plugins.ScenePlugin {
sprites: manifest.sprites || [],
audio: manifest.audio || [],
bitmapFonts: manifest.bitmapFonts || [],
spriteSheets: manifest.spriteSheets || []
};

// Define the loaders for the different asset types.
Expand All @@ -36,6 +37,7 @@ export default class WebpackLoader extends Phaser.Plugins.ScenePlugin {
sprites: this._loadSprite,
audio: this._loadAudio,
bitmapFonts: this._loadBitmapFont,
spriteSheets: this._loadSpriteSheet
};

// Define the postfix string to apply to image assets (ex: @2x).
Expand Down Expand Up @@ -154,4 +156,16 @@ export default class WebpackLoader extends Phaser.Plugins.ScenePlugin {
const data = require(`assets/${dir}${name}${this.postfix}.xml`);
this.scene.load.bitmapFont(name, file, data);
}

/**
* Load a sprite sheet.
* @param {String} name Name of the file.
* @param {String} ext File extension.
*/
_loadSpriteSheet(name, ext) {
const dir = 'spriteSheets/';
const file = require(`assets/${dir}${name}${this.postfix}.${ext}`);
const data = require(`assets/${dir}${name}${this.postfix}.json`);
this.scene.load.spritesheet(name, file, data);
}
}