-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 35e0174
Showing
18 changed files
with
1,139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "directory": "example/lib" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
example/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Nine Patch Phaser Plugin | ||
|
||
Nine Patch Phaser Plugin allows you to use [nine patch images](https://github.com/chrislondon/9-Patch-Image-for-Websites/wiki/What-Are-9-Patch-Images) in the HTML game framework [Phaser](http://phaser.io). | ||
|
||
This is not technically a Phaser Plugin. It provides two methods in `game.cache` to generate nine patch textures and a `Phaser.NinePatchImage` class to create nine patch images from these textures. | ||
|
||
The plugin is written using ES6 and compiled with [Babel](babeljs.io) and [Browserify](http://browserify.org/), tested on Phaser 2.1.3 and Phaser 2.4.3. | ||
|
||
## Usage | ||
|
||
Simply download the `nine-patch-phaser-plugin.js` or `nine-patch-phaser-plugin.min.js` script in the `build` folder and include it on your page after including Phaser: | ||
|
||
```html | ||
<script src="phaser.js"></script> | ||
<script src="nine-patch-phaser-plugin.js"></script> | ||
``` | ||
|
||
In the `create` method in your preloading states (to make sure the image/spritesheet/atlas is loaded), use `game.cache.addNinePatch` method to create the nine patch textures: | ||
```javascript | ||
game.cache.addNinePatch(name, key, frame, left, right, top, bottom); | ||
``` | ||
- `name` is the reference key that would be used later to get the nine patch textures | ||
- `key` is a key string of the image/spritesheet/atlas loaded | ||
- `frame` is the optional index of the frame if the nine patch image is on a spritesheet or atlas, can be either string or number | ||
- `left`, `right`, `top`, `bottom` are the left most, right most, top most and bottom most points of the center patch in the nine patch image. | ||
|
||
After that, in your game, you can create a nine patch image as follow: | ||
```javascript | ||
var image = new Phaser.NinePatchImage(game, x, y, name); | ||
``` | ||
with `name` is the reference key you specified before. | ||
|
||
To change the measures of the NinePatchImage, change the `targetWidth` and `targetHeight` properties. Also, remember that since Phaser.NinePatchImage actually extends Phaser.Image, so you can do anything that you can do on a Phaser.Image instance with a Phaser.NinePatchImage instance. However, in some cases, like with `anchor`, you have to run the method `UpdateImageSizes` for the NinePatchImage to be displayed correctly. | ||
|
||
Check the example in `example` folder to see it in action :) | ||
|
||
## Download | ||
|
||
The source is available for download by cloning the repository or download the files in `build` folder. Alternatively, you can install via: | ||
|
||
- [npm](https://www.npmjs.com/): `To be updated` | ||
- [bower](http://bower.io/): `To be updated` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "nine-patch-phaser-plugin", | ||
"version": "1.0.0", | ||
"authors": [ | ||
"Nguyen Tuan Anh <[email protected]>" | ||
], | ||
"description": "A Nine Patch Plugin for Phaser", | ||
"main": "build/nine-patch-phaser-plugin.min.js", | ||
"moduleType": [ | ||
"es6", | ||
"globals", | ||
"node" | ||
], | ||
"keywords": [ | ||
"phaser", | ||
"plugin", | ||
"nine", | ||
"patch", | ||
"9", | ||
"ninepatch", | ||
"9patch", | ||
"nine-patch", | ||
"9-patch" | ||
], | ||
"license": "MIT", | ||
"homepage": "http://anhnt.ninja", | ||
"ignore": [ | ||
"node_modules", | ||
"bower_components" | ||
], | ||
"dependencies": { | ||
"dat-gui": "~0.5.1", | ||
"phaser": "~2.4.3" | ||
} | ||
} |
Oops, something went wrong.