Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
netcell committed Aug 26, 2015
0 parents commit 35e0174
Show file tree
Hide file tree
Showing 18 changed files with 1,139 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "directory": "example/lib" }
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
example/lib
42 changes: 42 additions & 0 deletions README.md
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`
35 changes: 35 additions & 0 deletions bower.json
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"
}
}
Loading

0 comments on commit 35e0174

Please sign in to comment.