diff --git a/README.md b/README.md
index b3b2c717..8efe2dc6 100644
--- a/README.md
+++ b/README.md
@@ -44,10 +44,12 @@ Version 1.1.3 - in build
* New: Added a .jshintrc so contributions can be run through JSHint to help retain formatting across the library (thanks kevinthompson)
* New: The entire Phaser library has been updated to match the new JSHint configuration.
* New: Added a new in-built texture. Sprites now use __default if no texture was provided (a 32x32 transparent PNG) or __missing if one was given but not found (a 32x32 black box with a green cross through it)
-* New: Added Phaser.Filter. A new way to use the new WebGL shaders/filters that the new version of Pixi supports.
-* New: The object returned by Math.sinCosGenerator now contains a length property.
+* New: Phaser.Filter. A new way to use the new WebGL shaders/filters that the new version of Pixi supports.
* New: Phaser.BitmapData object. A Canvas you can freely draw to with lots of functions. Can be used as a texture for Sprites. See the new examples and docs for details.
* New: RenderTexture.render now takes a Phaser.Group. Also added renderXY for when you don't want to make a new Point object.
+* New: Physics.overlap now supports Sprites, Groups or Emitters and can perform group vs. group (etc) overlap checks with a custom callback and process handler.
+* New: Added Sound.externalNode which allows you to connect a Sound to an external node input rather than the SoundManager gain node.
+* New: Added SoundManager.connectToMaster boolean. Used in conjunction with Sound.externalNode you can easily configure audio nodes to connect together for special effects.
* New: PluginManager.remove, added PluginManager.removeAll (thanks crazysam)
* New: scrollFactorX/scrollFactorY have been added to TilemapLayers (thanks jcd-as)
* New: Phaser.Game parent can now be an HTMLElement or a string (thanks beeglebug)
@@ -64,8 +66,22 @@ Version 1.1.3 - in build
* New: Device.littleEndian boolean added. Only safe to use if the browser supports TypedArrays (which IE9 doesn't, but nearly all others do)
* New: You can now call game.sound.play() and simply pass it a key. The sound will play if the audio system is unlocked and optionally destroy itself on complete.
* New: Mouse.capture is a boolean. If set to true then DOM mouse events will have event.preventDefault() applied, if false they will propogate fully.
-* New: Added Sound.externalNode which allows you to connect a Sound to an external node input rather than the SoundManager gain node.
-* New: Added SoundManager.connectToMaster boolean. Used in conjunction with Sound.externalNode you can easily configure audio nodes to connect together for special effects.
+* New: The object returned by Math.sinCosGenerator now contains a length property.
+
+* Updated: Lots of documentation fixes and updates across nearly all files. Tilemap now documented for example and lots of instances of 'Description' filled out.
+* Updated: ArcadePhysics.updateMotion applies the dt to the velocity calculations as well as position now (thanks jcs)
+* Updated: RequestAnimationFrame now retains the callbackID which is passed to cancelRequestAnimationFrame.
+* Updated: Button now goes back to over state when setFrames used in action (thanks beeglebug)
+* Updated: plugins now have a postUpdate callback (thanks cocoademon)
+* Updated: Tided up the Graphics object (thanks BorisKozo)
+* Updated: If running in Canvas mode and you have a render function it will save the context and reset the transform before running your render function.
+* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
+* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
+* Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)
+* Updated: Loader.audio can now accept either an array of URL strings or a single URL string (thanks crazysam + kevinthompson)
+* Updated: MSPointer updated to support IE11 by dropping the prefix from the event listeners.
+* Updated: Device.cocoonJS added to detect if the game is running under Cocoon or a native browser.
+* Updated: Loader now uses a new queue system internally, meaning you can have assets with the same key spread across different types.
* Fixed: Lots of fixes to the TypeScript definitions file (many thanks gltovar)
* Fixed: Tilemap commands use specified layer when one given (thanks Izzimach)
@@ -82,20 +98,7 @@ Version 1.1.3 - in build
* Fixed: Device.isTouch modified to test maxTouchPointers instead of MSPointer.
* Fixed: InputHandler.checkPointerOver now checks the visible status of the Sprite Group before processing.
* Fixed: The Sprite hulls (used for tile collision) were not being updated in sprite->sprite separations (thanks jcs)
-
-* Updated: ArcadePhysics.updateMotion applies the dt to the velocity calculations as well as position now (thanks jcs)
-* Updated: RequestAnimationFrame now retains the callbackID which is passed to cancelRequestAnimationFrame.
-* Updated: Button now goes back to over state when setFrames used in action (thanks beeglebug)
-* Updated: plugins now have a postUpdate callback (thanks cocoademon)
-* Updated: Tided up the Graphics object (thanks BorisKozo)
-* Updated: If running in Canvas mode and you have a render function it will save the context and reset the transform before running your render function.
-* Updated: Sprite will now check the exists property of the Group it is in, if the Group.exists = false the Sprite won't update.
-* Updated: Lots of documentation fixes and updates across nearly all files.
-* Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked)
-* Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)
-* Updated: Loader.audio can now accept either an array of URL strings or a single URL string (thanks crazysam + kevinthompson)
-* Updated: MSPointer updated to support IE11 by dropping the prefix from the event listeners.
-* Updated: Device.cocoonJS added to detect if the game is running under Cocoon or a native browser.
+* Fixed: Plugins that had a postUpdate but no Update weren't being marked as active (thanks crazysam)
You can view the complete Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md
@@ -211,12 +214,6 @@ The 1.1 release was a massive under-taking, but we're really happy with how Phas
* Create more touch input examples (http://www.html5gamedevs.com/topic/1556-mobile-touch-event/)
* Look at HiDPI Canvas settings.
-Some specific features / issues we will address soon:
-
-* Loader conflict if 2 keys are the same even if they are in different packages (i.e. you can't use "title" for both and image and sound file).
-* Sound.addMarker hh:mm:ss:ms.
-* Add support for a rotation offset.
-
Learn By Example
----------------
@@ -243,10 +240,10 @@ If you find a bug (highly likely!) then please report it on github or our forum.
If you have a feature request, or have written a small game or demo that shows Phaser in use, then please get in touch. We'd love to hear from you.
-Before submitting a pull request, please run your code through [JSHint](http://www.jshint.com/) to check for stylistic or formatting errors. To use JSHint, first install it by running `npm install jshint`, then test your code by running `jshint src`. This isn't a requirement, we are happy to receive pull requests that haven't been JSHinted, so don't let it put you off contributing - but do know that we'll reformat your source before going live with it.
-
You can do this on the Phaser board that is part of the [HTML5 Game Devs forum](http://www.html5gamedevs.com/forum/14-phaser/) or email: rich@photonstorm.com
+Before submitting a pull request, please run your code through [JSHint](http://www.jshint.com/) to check for stylistic or formatting errors. To use JSHint, first install it by running `npm install jshint`, then test your code by running `jshint src`. This isn't a requirement, we are happy to receive pull requests that haven't been JSHinted, so don't let it put you off contributing - but do know that we'll reformat your source before going live with it.
+
Bugs?
-----
diff --git a/build/phaser.d.ts b/build/phaser.d.ts
index 847ec2bf..f7c84f8a 100644
--- a/build/phaser.d.ts
+++ b/build/phaser.d.ts
@@ -1565,6 +1565,10 @@ declare module Phaser {
computeVelocity(axis: number, body: Phaser.Physics.Arcade.Body, velocity: number, acceleration: number, drag: number, max: number): void;
preUpdate(): void;
postUpdate(): void;
+ overlap(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
+ overlapSpriteVsSprite(sprite1: Phaser.Sprite, sprite2: Phaser.Sprite, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
+ overlapSpriteVsGroup(sprite1: Phaser.Sprite, group: Phaser.Group, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
+ overlapGroupVsGroup(group: Phaser.Group, group2: Phaser.Group, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
collide(object1: any, object2: any, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
collideSpriteVsSprite(sprite1: Phaser.Sprite, sprite2: Phaser.Sprite, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
collideSpriteVsTilemap(sprite1: Phaser.Sprite, tilemap: Phaser.Tilemap, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
diff --git a/build/ts.bat b/build/ts.bat
deleted file mode 100644
index 7b415531..00000000
--- a/build/ts.bat
+++ /dev/null
@@ -1 +0,0 @@
-jsdocts -d:phaser.d.ts phaser.js
\ No newline at end of file
diff --git a/docs/build/conf.json b/docs/build/conf.json
index 4bbe4e6c..95acdf2a 100644
--- a/docs/build/conf.json
+++ b/docs/build/conf.json
@@ -18,6 +18,7 @@
"../../src/physics/arcade/",
"../../src/sound/",
"../../src/system/",
+ "../../src/tilemap/",
"../../src/time/",
"../../src/tween/",
"../../src/utils/"
diff --git a/docs/build/conf_dev.json b/docs/build/conf_dev.json
index 4bbe4e6c..95acdf2a 100644
--- a/docs/build/conf_dev.json
+++ b/docs/build/conf_dev.json
@@ -18,6 +18,7 @@
"../../src/physics/arcade/",
"../../src/sound/",
"../../src/system/",
+ "../../src/tilemap/",
"../../src/time/",
"../../src/tween/",
"../../src/utils/"
diff --git a/examples/_site/examples.json b/examples/_site/examples.json
index 31414920..74a16373 100644
--- a/examples/_site/examples.json
+++ b/examples/_site/examples.json
@@ -392,6 +392,10 @@
"file": "load+audio.js",
"title": "load audio"
},
+ {
+ "file": "load+bitmap+font.js",
+ "title": "load bitmap font"
+ },
{
"file": "load+image.js",
"title": "load image"
@@ -400,6 +404,18 @@
"file": "load+spritesheet.js",
"title": "load spritesheet"
},
+ {
+ "file": "load+starling+atlas.js",
+ "title": "load starling atlas"
+ },
+ {
+ "file": "load+text+file.js",
+ "title": "load text file"
+ },
+ {
+ "file": "load+texture+atlas.js",
+ "title": "load texture atlas"
+ },
{
"file": "pick+images+from+cache.js",
"title": "pick images from cache"
@@ -592,6 +608,10 @@
"file": "animated+tiling+sprite.js",
"title": "animated tiling sprite"
},
+ {
+ "file": "tiling+sprite+input.js",
+ "title": "tiling sprite input"
+ },
{
"file": "tiling+sprite.js",
"title": "tiling sprite"
diff --git a/examples/loader/load audio.js b/examples/loader/load audio.js
index a92cdad5..614c7c60 100644
--- a/examples/loader/load audio.js
+++ b/examples/loader/load audio.js
@@ -1,5 +1,5 @@
-var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
+var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
function preload() {
@@ -14,6 +14,9 @@ function preload() {
game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']);
+ // If you know you only need to load 1 type of audio file, you can pass a string instead of an array, like this:
+ // game.load.audio('boden', 'assets/audio/bodenstaendig_2000_in_rock_4bit.mp3');
+
}
var music;
@@ -22,8 +25,6 @@ function create() {
game.stage.backgroundColor = '#182d3b';
- // game.input.touch.preventDefault = false;
-
music = game.sound.play('boden');
}
@@ -32,4 +33,9 @@ function render() {
game.debug.renderSoundInfo(music, 32, 32);
+ if (music.isDecoding)
+ {
+ game.debug.renderText("Decoding MP3 ...", 32, 200);
+ }
+
}
diff --git a/examples/loader/load bitmap font.js b/examples/loader/load bitmap font.js
new file mode 100644
index 00000000..6523470d
--- /dev/null
+++ b/examples/loader/load bitmap font.js
@@ -0,0 +1,36 @@
+
+var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
+
+function preload() {
+
+ // Phaser can load Bitmap Fonts.
+
+ // As with all load operations the first parameter is a unique key, which must be unique between all image files.
+ // Next is the bitmap font file itself, in this case desyrel.png
+ // Finally is the path to the XML file that goes with the font.
+
+ game.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml');
+
+ // Note that the XML file should be saved with UTF-8 encoding or some browsers (such as Firefox) won't load it.
+
+ // There are various tools that can create Bitmap Fonts and the XML file needed.
+ // On Windows you can use the free app BMFont: http://www.angelcode.com/products/bmfont/
+ // On OS X we recommend Glyph Designer: http://www.71squared.com/en/glyphdesigner
+
+}
+
+var text;
+
+function create() {
+
+ game.stage.backgroundColor = '#0072bc';
+
+ text = game.add.bitmapText(200, 100, 'Bitmap Fonts!', { font: '64px Desyrel', align: 'center' });
+
+}
+
+function update() {
+
+ text.setText('Bitmap Fonts!\nx: ' + Math.round(game.input.x) + ' y: ' + Math.round(game.input.y));
+
+}
diff --git a/examples/loader/load starling atlas.js b/examples/loader/load starling atlas.js
new file mode 100644
index 00000000..5cb9195f
--- /dev/null
+++ b/examples/loader/load starling atlas.js
@@ -0,0 +1,38 @@
+
+var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
+
+function preload() {
+
+ // Phaser can load texture atlas files that use the Starling XML file format.
+
+ // As with all load operations the first parameter is a unique key, which must be unique between all image files.
+
+ // Next is the texture atlas itself, in this case seacreatures.png
+ // Finally is the path to the XML file that goes with the atlas.
+ game.load.atlasXML('seacreatures', 'assets/sprites/seacreatures.png', 'assets/sprites/seacreatures.xml');
+
+ // Note that the XML file should be saved with UTF-8 encoding or some browsers (such as Firefox) won't load it.
+
+
+
+ // These are just a few images to use in our underwater scene.
+ game.load.image('undersea', 'assets/pics/undersea.jpg');
+ game.load.image('coral', 'assets/pics/seabed.png');
+
+}
+
+var jellyfish;
+
+function create() {
+
+ game.add.sprite(0, 0, 'undersea');
+
+ jellyfish = game.add.sprite(330, 100, 'seacreatures');
+ jellyfish.animations.add('swim', Phaser.Animation.generateFrameNames('greenJellyfish', 0, 39, '', 4), 30, true);
+ jellyfish.animations.play('swim');
+
+ game.add.sprite(0, 466, 'coral');
+
+ game.add.tween(jellyfish).to({ y: 250 }, 4000, Phaser.Easing.Quadratic.InOut, true, 0, 10000, true);
+
+}
diff --git a/examples/loader/load text file.js b/examples/loader/load text file.js
new file mode 100644
index 00000000..5772157c
--- /dev/null
+++ b/examples/loader/load text file.js
@@ -0,0 +1,37 @@
+
+var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
+
+function preload() {
+
+ // Phaser can load Text files.
+
+ // It does this using an XMLHttpRequest.
+
+ // If loading a file from outside of the domain in which the game is running
+ // a 'Access-Control-Allow-Origin' header must be present on the server.
+ // No parsing of the text file is performed, it's literally just the raw data.
+
+ game.load.text('html', 'http://phaser.io');
+
+}
+
+var text;
+
+function create() {
+
+ game.stage.backgroundColor = '#0072bc';
+
+ var html = game.cache.getText('html');
+
+ text = html.split('\n');
+
+}
+
+function render() {
+
+ for (var i = 0; i < 30; i++)
+ {
+ game.debug.renderText(text[i], 32, i * 20);
+ }
+
+}
diff --git a/examples/loader/load texture atlas.js b/examples/loader/load texture atlas.js
new file mode 100644
index 00000000..57e523b7
--- /dev/null
+++ b/examples/loader/load texture atlas.js
@@ -0,0 +1,39 @@
+
+var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
+
+function preload() {
+
+ // Phaser can load Texture Atlas files that use either JSON Hash or JSON Array format.
+
+ // As with all load operations the first parameter is a unique key, which must be unique between all image files.
+
+ // Next is the texture atlas itself, in this case seacreatures.png
+
+ // Finally is the path to the JSON file that goes with the atlas.
+ game.load.atlas('seacreatures', 'assets/sprites/seacreatures_json.png', 'assets/sprites/seacreatures_json.json');
+
+ // Note that the JSON file should be saved with UTF-8 encoding or some browsers (such as Firefox) won't load it.
+
+
+
+ // These are just a few images to use in our underwater scene.
+ game.load.image('undersea', 'assets/pics/undersea.jpg');
+ game.load.image('coral', 'assets/pics/seabed.png');
+
+}
+
+var octopus;
+
+function create() {
+
+ game.add.sprite(0, 0, 'undersea');
+
+ octopus = game.add.sprite(330, 100, 'seacreatures');
+ octopus.animations.add('swim', Phaser.Animation.generateFrameNames('octopus', 0, 24, '', 4), 30, true);
+ octopus.animations.play('swim');
+
+ game.add.tween(octopus).to({ y: 250 }, 4000, Phaser.Easing.Quadratic.InOut, true, 0, 10000, true);
+
+ game.add.sprite(0, 466, 'coral');
+
+}
diff --git a/examples/wip/bunny.js b/examples/wip/bunny.js
new file mode 100644
index 00000000..a86a6a8e
--- /dev/null
+++ b/examples/wip/bunny.js
@@ -0,0 +1,55 @@
+
+ GameState = function (game) {
+ this.game = game;
+ };
+
+ GameState.prototype = Object.create(Phaser.State.prototype);
+ GameState.prototype.constructor = GameState;
+
+ GameState.prototype.preload = function preload() {
+ this.game.load.image('bunny', 'assets/sprites/bunny.png');
+ this.game.load.image('carrot', 'assets/sprites/carrot.png');
+ this.game.load.image('melon', 'assets/sprites/melon.png');
+ }
+
+ GameState.prototype.create = function () {
+ this.game.world.setBounds(0, 0, 1600, 600);
+
+ this.bunny = this.game.add.sprite(200, 200, 'bunny');
+ this.bunny.scale.setTo(0.2, 0.2);
+
+ var melon = this.game.add.sprite(0, 0, 'melon');
+ this.melonGroup = this.game.add.group(null, 'melonGroup');
+ this.melonGroup.add(melon);
+ melon.x = this.bunny.x;
+ melon.y = this.bunny.y - 40;
+
+ this.carrot = this.game.add.sprite(0, 0, 'carrot');
+
+ this.game.camera.follow(this.bunny);
+ }
+
+ GameState.prototype.update = function () {
+ this.bunny.body.velocity.x = 0;
+
+ if (this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
+ this.bunny.body.velocity.x = 500;
+ }
+
+ if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
+ this.bunny.body.velocity.x = -500;
+ }
+
+ // var melon = this.melonGroup.getFirstExists(true);
+ // melon.x = this.bunny.x;
+ // melon.y = this.bunny.y - 40;
+
+ this.carrot.x = this.bunny.x;
+ this.carrot.y = this.bunny.y - 20;
+
+ };
+
+ (function () {
+ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example');
+ game.state.add('state', GameState, true);
+ })();
diff --git a/examples/wip/button scale.js b/examples/wip/button scale.js
index ac3ae049..45d791b3 100644
--- a/examples/wip/button scale.js
+++ b/examples/wip/button scale.js
@@ -32,6 +32,8 @@ var button6;
function create() {
+ console.log('create!');
+
background = game.add.sprite(0, 0, 'sky0');
background.name = 'background';
@@ -77,7 +79,7 @@ function create() {
// Phaser.Canvas.setSmoothingEnabled(false);
- game.input.onDown.add(gofull, this);
+ //game.input.onDown.add(gofull, this);
}
diff --git a/src/IntroDocs.js b/src/IntroDocs.js
index 12be2435..323a0f43 100644
--- a/src/IntroDocs.js
+++ b/src/IntroDocs.js
@@ -9,7 +9,7 @@
*
* Phaser - http://www.phaser.io
*
-* v1.1.2 - Released November 1st 2013.
+* v1.1.3 - Released November 28th 2013.
*
* By Richard Davey http://www.photonstorm.com @photonstorm
*
diff --git a/src/core/Filter.js b/src/core/Filter.js
index c3c67303..bfaf9b26 100644
--- a/src/core/Filter.js
+++ b/src/core/Filter.js
@@ -67,10 +67,21 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
Phaser.Filter.prototype = {
+ /**
+ * Should be over-ridden.
+ * @method Phaser.Filter#init
+ * @param {...}
+ */
init: function () {
// This should be over-ridden. Will receive a variable number of arguments.
},
+ /**
+ * Set the resolution uniforms on the filter.
+ * @method Phaser.Filter#setResolution
+ * @param {number} width - The width of the display.
+ * @param {number} height - The height of the display.
+ */
setResolution: function (width, height) {
this.uniforms.resolution.value.x = width;
@@ -78,6 +89,11 @@ Phaser.Filter.prototype = {
},
+ /**
+ * Updates the filter.
+ * @method Phaser.Filter#update
+ * @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
+ */
update: function (pointer) {
if (typeof pointer !== 'undefined')
@@ -102,6 +118,10 @@ Phaser.Filter.prototype = {
};
+/**
+* @name Phaser.Filter#width
+* @property {number} width - The width (resolution uniform)
+*/
Object.defineProperty(Phaser.Filter.prototype, 'width', {
get: function() {
@@ -114,6 +134,10 @@ Object.defineProperty(Phaser.Filter.prototype, 'width', {
});
+/**
+* @name Phaser.Filter#height
+* @property {number} height - The height (resolution uniform)
+*/
Object.defineProperty(Phaser.Filter.prototype, 'height', {
get: function() {
diff --git a/src/core/Group.js b/src/core/Group.js
index bc57be0e..d7bed67c 100644
--- a/src/core/Group.js
+++ b/src/core/Group.js
@@ -197,7 +197,6 @@ Phaser.Group.prototype = {
* Returns the child found at the given index within this Group.
*
* @method Phaser.Group#getAt
- * @memberof Phaser.Group
* @param {number} index - The index to return the child from.
* @return {*} The child that was found at the given index.
*/
diff --git a/src/core/PluginManager.js b/src/core/PluginManager.js
index 1ca1f92d..2e353890 100644
--- a/src/core/PluginManager.js
+++ b/src/core/PluginManager.js
@@ -100,7 +100,7 @@ Phaser.PluginManager.prototype = {
// The plugin must have at least one of the above functions to be added to the PluginManager.
if (result)
{
- if (plugin.hasPreUpdate || plugin.hasUpdate)
+ if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate)
{
plugin.active = true;
}
diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js
index 1cf92f7f..2df513b6 100644
--- a/src/gameobjects/Sprite.js
+++ b/src/gameobjects/Sprite.js
@@ -1099,6 +1099,8 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
set: function (value) {
+ console.log('inputEnabled', value, this.input);
+
if (value)
{
if (this.input.enabled === false)
diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js
index 5bcdd291..9bd137ed 100644
--- a/src/input/InputHandler.js
+++ b/src/input/InputHandler.js
@@ -199,6 +199,8 @@ Phaser.InputHandler.prototype = {
*/
start: function (priority, useHandCursor) {
+ console.log('InputHandler start');
+
priority = priority || 0;
if (typeof useHandCursor == 'undefined') { useHandCursor = false; }
diff --git a/src/input/Mouse.js b/src/input/Mouse.js
index 75c69983..812c35b9 100644
--- a/src/input/Mouse.js
+++ b/src/input/Mouse.js
@@ -41,7 +41,7 @@ Phaser.Mouse = function (game) {
/**
* @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propogate fully.
*/
- this.capture = true;
+ this.capture = false;
/**
* @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON.
@@ -144,10 +144,6 @@ Phaser.Mouse.prototype = {
return _this.onMouseUp(event);
};
- // this.game.renderer.view.addEventListener('mousedown', this._onMouseDown, true);
- // this.game.renderer.view.addEventListener('mousemove', this._onMouseMove, true);
- // this.game.renderer.view.addEventListener('mouseup', this._onMouseUp, true);
-
document.addEventListener('mousedown', this._onMouseDown, true);
document.addEventListener('mousemove', this._onMouseMove, true);
document.addEventListener('mouseup', this._onMouseUp, true);
@@ -323,10 +319,6 @@ Phaser.Mouse.prototype = {
*/
stop: function () {
- // this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown, true);
- // this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove, true);
- // this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp, true);
-
document.removeEventListener('mousedown', this._onMouseDown, true);
document.removeEventListener('mousemove', this._onMouseMove, true);
document.removeEventListener('mouseup', this._onMouseUp, true);
diff --git a/src/loader/Loader.js b/src/loader/Loader.js
index 42220a4c..22df8861 100644
--- a/src/loader/Loader.js
+++ b/src/loader/Loader.js
@@ -244,8 +244,6 @@ Phaser.Loader.prototype = {
loaded: false
};
- console.log('addToFileList', entry);
-
if (typeof properties !== "undefined")
{
for (var prop in properties)
@@ -681,8 +679,6 @@ Phaser.Loader.prototype = {
*/
start: function () {
- console.log('Loader start', this._fileList);
-
if (this.isLoading)
{
return;
@@ -887,8 +883,6 @@ Phaser.Loader.prototype = {
*/
fileComplete: function (index) {
-console.log('fileComplete', index);
-
if (!this._fileList[index])
{
console.warn('Phaser.Loader fileComplete invalid index ' + index);
@@ -997,7 +991,7 @@ console.log('fileComplete', index);
this.game.sound.context.decodeAudioData(file.data, function (buffer) {
if (buffer)
{
- that.game.cache.decodedSound(index, buffer);
+ that.game.cache.decodedSound(key, buffer);
}
});
}
diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js
index ce4bcab4..570b3b2e 100644
--- a/src/physics/arcade/ArcadePhysics.js
+++ b/src/physics/arcade/ArcadePhysics.js
@@ -282,22 +282,179 @@ Phaser.Physics.Arcade.prototype = {
},
/**
- * Checks if two Sprite objects overlap.
+ * Checks for overlaps between two game objects. The objects can be Sprites, Groups or Emitters.
+ * You can perform Sprite vs. Sprite, Sprite vs. Group and Group vs. Group overlap checks.
+ * Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results.
*
* @method Phaser.Physics.Arcade#overlap
- * @param {Phaser.Sprite} object1 - The first object to check. Can be an instance of Phaser.Sprite or anything that extends it.
- * @param {Phaser.Sprite} object2 - The second object to check. Can be an instance of Phaser.Sprite or anything that extends it.
- * @returns {boolean} true if the two objects overlap.
+ * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter} object1 - The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter.
+ * @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter} object2 - The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter.
+ * @param {function} [overlapCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them.
+ * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then overlapCallback will only be called if processCallback returns true.
+ * @param {object} [callbackContext] - The context in which to run the callbacks.
+ * @returns {boolean} True if an overlap occured otherwise false.
*/
- overlap: function (object1, object2) {
+ overlap: function (object1, object2, overlapCallback, processCallback, callbackContext) {
+
+ overlapCallback = overlapCallback || null;
+ processCallback = processCallback || null;
+ callbackContext = callbackContext || overlapCallback;
+
+ this._result = false;
+ this._total = 0;
// Only test valid objects
if (object1 && object2 && object1.exists && object2.exists)
{
- return (Phaser.Rectangle.intersects(object1.body, object2.body));
+ // SPRITES
+ if (object1.type == Phaser.SPRITE)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.overlapSpriteVsSprite(object1, object2, overlapCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.overlapSpriteVsGroup(object1, object2, overlapCallback, processCallback, callbackContext);
+ }
+ }
+ // GROUPS
+ else if (object1.type == Phaser.GROUP)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.overlapGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext);
+ }
+ }
+ // EMITTER
+ else if (object1.type == Phaser.EMITTER)
+ {
+ if (object2.type == Phaser.SPRITE)
+ {
+ this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
+ }
+ else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
+ {
+ this.overlapGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext);
+ }
+ }
}
- return false;
+ return (this._total > 0);
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.overlap instead.
+ *
+ * @method Phaser.Physics.Arcade#overlapSpriteVsSprite
+ * @private
+ */
+ overlapSpriteVsSprite: function (sprite1, sprite2, overlapCallback, processCallback, callbackContext) {
+
+ this._result = Phaser.Rectangle.intersects(sprite1.body, sprite2.body);
+
+ if (this._result)
+ {
+ // They collided, is there a custom process callback?
+ if (processCallback)
+ {
+ if (processCallback.call(callbackContext, sprite1, sprite2))
+ {
+ this._total++;
+
+ if (overlapCallback)
+ {
+ overlapCallback.call(callbackContext, sprite1, sprite2);
+ }
+ }
+ }
+ else
+ {
+ this._total++;
+
+ if (overlapCallback)
+ {
+ overlapCallback.call(callbackContext, sprite1, sprite2);
+ }
+ }
+ }
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.overlap instead.
+ *
+ * @method Phaser.Physics.Arcade#overlapSpriteVsGroup
+ * @private
+ */
+ overlapSpriteVsGroup: function (sprite, group, overlapCallback, processCallback, callbackContext) {
+
+ if (group.length === 0)
+ {
+ return;
+ }
+
+ // What is the sprite colliding with in the quadtree?
+ this._potentials = this.quadTree.retrieve(sprite);
+
+ for (var i = 0, len = this._potentials.length; i < len; i++)
+ {
+ // We have our potential suspects, are they in this group?
+ if (this._potentials[i].sprite.group == group)
+ {
+ this._result = Phaser.Rectangle.intersects(sprite.body, this._potentials[i]);
+
+ if (this._result && processCallback)
+ {
+ this._result = processCallback.call(callbackContext, sprite, this._potentials[i].sprite);
+ }
+
+ if (this._result)
+ {
+ this._total++;
+
+ if (overlapCallback)
+ {
+ overlapCallback.call(callbackContext, sprite, this._potentials[i].sprite);
+ }
+ }
+ }
+ }
+
+ },
+
+ /**
+ * An internal function. Use Phaser.Physics.Arcade.overlap instead.
+ *
+ * @method Phaser.Physics.Arcade#overlapGroupVsGroup
+ * @private
+ */
+ overlapGroupVsGroup: function (group1, group2, overlapCallback, processCallback, callbackContext) {
+
+ if (group1.length === 0 || group2.length === 0)
+ {
+ return;
+ }
+
+ if (group1._container.first._iNext)
+ {
+ var currentNode = group1._container.first._iNext;
+
+ do
+ {
+ if (currentNode.exists)
+ {
+ this.overlapSpriteVsGroup(currentNode, group2, overlapCallback, processCallback, callbackContext);
+ }
+ currentNode = currentNode._iNext;
+ }
+ while (currentNode != group1._container.last._iNext);
+ }
},
@@ -309,10 +466,10 @@ Phaser.Physics.Arcade.prototype = {
* @method Phaser.Physics.Arcade#collide
* @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object1 - The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.Tilemap
* @param {Phaser.Sprite|Phaser.Group|Phaser.Particles.Emitter|Phaser.Tilemap} object2 - The second object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.Tilemap
- * @param {function} [collideCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
+ * @param {function} [collideCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them.
* @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true.
* @param {object} [callbackContext] - The context in which to run the callbacks.
- * @returns {number} The number of collisions that were processed.
+ * @returns {boolean} True if a collision occured otherwise false.
*/
collide: function (object1, object2, collideCallback, processCallback, callbackContext) {
diff --git a/src/tilemap/Tile.js b/src/tilemap/Tile.js
index 3fb2ae84..8a03ebaf 100644
--- a/src/tilemap/Tile.js
+++ b/src/tilemap/Tile.js
@@ -6,21 +6,22 @@
*/
/**
-* Create a new Tile.
+* Create a new `Tile` object. Tiles live inside of Tilesets and are rendered via TilemapLayers.
*
* @class Phaser.Tile
* @classdesc A Tile is a single representation of a tile within a Tilemap.
* @constructor
-* @param {Phaser.Game} game - A reference to the currently running game.
-* @param {Tilemap} tilemap - The tilemap this tile belongs to.
-* @param {number} index - The index of this tile type in the core map data.
-* @param {number} width - Width of the tile.
-* @param {number} height - Height of the tile.
+* @param {Phaser.Tileset} tileset - The tileset this tile belongs to.
+* @param {number} index - The index of this tile type in the core map data.
+* @param {number} x - The x coordinate of this tile.
+* @param {number} y - The y coordinate of this tile.
+* @param {number} width - Width of the tile.
+* @param {number} height - Height of the tile.
*/
Phaser.Tile = function (tileset, index, x, y, width, height) {
/**
- * @property {string} tileset - The tileset this tile belongs to.
+ * @property {Phaser.Tileset} tileset - The tileset this tile belongs to.
*/
this.tileset = tileset;
@@ -118,7 +119,7 @@ Phaser.Tile.prototype = {
/**
* Set callback to be called when this tilemap collides.
*
- * @method Phaser.Tilemap.prototype.setCollisionCallback
+ * @method Phaser.Tile#setCollisionCallback
* @param {Function} callback - Callback function.
* @param {object} context - Callback will be called with this context.
*/
@@ -131,7 +132,7 @@ Phaser.Tile.prototype = {
/**
* Clean up memory.
- * @method destroy
+ * @method Phaser.Tile#destroy
*/
destroy: function () {
@@ -140,15 +141,12 @@ Phaser.Tile.prototype = {
},
/**
- * Set collision configs.
- * @method setCollision
- * @param {boolean} left - Indicating collide with any object on the left.
- * @param {boolean} right - Indicating collide with any object on the right.
- * @param {boolean} up - Indicating collide with any object on the top.
- * @param {boolean} down - Indicating collide with any object on the bottom.
- * @param {boolean} reset - Description.
- * @param {boolean} separateX - Separate at x-axis.
- * @param {boolean} separateY - Separate at y-axis.
+ * Set collision settings on this tile.
+ * @method Phaser.Tile#setCollision
+ * @param {boolean} left - Indicating collide with any object on the left.
+ * @param {boolean} right - Indicating collide with any object on the right.
+ * @param {boolean} up - Indicating collide with any object on the top.
+ * @param {boolean} down - Indicating collide with any object on the bottom.
*/
setCollision: function (left, right, up, down) {
@@ -170,7 +168,7 @@ Phaser.Tile.prototype = {
/**
* Reset collision status flags.
- * @method resetCollision
+ * @method Phaser.Tile#resetCollision
*/
resetCollision: function () {
@@ -184,27 +182,26 @@ Phaser.Tile.prototype = {
};
+/**
+* @name Phaser.Tile#bottom
+* @property {number} bottom - The sum of the y and height properties.
+* @readonly
+*/
Object.defineProperty(Phaser.Tile.prototype, "bottom", {
- /**
- * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
- * @method bottom
- * @return {number}
- */
get: function () {
return this.y + this.height;
}
});
+/**
+* @name Phaser.Tile#right
+* @property {number} right - The sum of the x and width properties.
+* @readonly
+*/
Object.defineProperty(Phaser.Tile.prototype, "right", {
- /**
- * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
- * However it does affect the width property.
- * @method right
- * @return {number}
- */
get: function () {
return this.x + this.width;
}
diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js
index 6999ef3a..07b34872 100644
--- a/src/tilemap/Tilemap.js
+++ b/src/tilemap/Tilemap.js
@@ -1,12 +1,27 @@
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* A Tile Map object. A Tile map consists of a set of tile data and tile sets. It is rendered to the display using a TilemapLayer.
+* A map may have multiple layers. You can perform operations on the map data such as copying, pasting, filling and shuffling the tiles around.
+*
+* @class Phaser.Tilemap
+* @constructor
+* @param {Phaser.Game} game - Game reference to the currently running game.
+* @param {string} [key] - The key of the tilemap data as stored in the Cache.
+*/
Phaser.Tilemap = function (game, key) {
/**
- * @property {Phaser.Game} game - Description.
+ * @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
- * @property {array} layers - Description.
+ * @property {array} layers - An array of Tilemap layers.
*/
this.layers = null;
@@ -22,23 +37,64 @@ Phaser.Tilemap = function (game, key) {
this.layers = [];
}
+ /**
+ * @property {number} currentLayer - The current layer.
+ */
this.currentLayer = 0;
+ /**
+ * @property {array} debugMap - Map data used for debug values only.
+ */
+
this.debugMap = [];
+ /**
+ * @property {boolean} dirty - Internal rendering related flag.
+ */
this.dirty = false;
+ /**
+ * @property {array} _results - Internal var.
+ * @private
+ */
this._results = [];
+
+ /**
+ * @property {number} _tempA - Internal var.
+ * @private
+ */
this._tempA = 0;
+
+ /**
+ * @property {number} _tempB - Internal var.
+ * @private
+ */
this._tempB = 0;
};
+/**
+* @constant
+* @type {number}
+*/
Phaser.Tilemap.CSV = 0;
+
+/**
+* @constant
+* @type {number}
+*/
Phaser.Tilemap.TILED_JSON = 1;
Phaser.Tilemap.prototype = {
+ /**
+ * Creates an empty map of the given dimensions.
+ *
+ * @method Phaser.Tilemap#create
+ * @param {string} name - The name of the map (mostly used for debugging)
+ * @param {number} width - The width of the map in tiles.
+ * @param {number} height - The height of the map in tiles.
+ */
create: function (name, width, height) {
var data = [];
@@ -53,7 +109,7 @@ Phaser.Tilemap.prototype = {
}
}
- this.currentLayer = this.layers.push({
+ this.layers.push({
name: name,
width: width,
@@ -68,10 +124,17 @@ Phaser.Tilemap.prototype = {
});
+ this.currentLayer = this.layers.length - 1;
+
this.dirty = true;
},
+ /**
+ * Internal function that calculates the tile indexes for the map data.
+ *
+ * @method Phaser.Tilemap#calculateIndexes
+ */
calculateIndexes: function () {
for (var layer = 0; layer < this.layers.length; layer++)
@@ -94,6 +157,12 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Sets the current layer to the given index.
+ *
+ * @method Phaser.Tilemap#setLayer
+ * @param {number} layer - Sets the current layer to the given index.
+ */
setLayer: function (layer) {
if (this.layers[layer])
@@ -104,11 +173,12 @@ Phaser.Tilemap.prototype = {
},
/**
- * Set a specific tile with its x and y in tiles.
- * @method putTile
- * @param {number} x - X position of this tile.
- * @param {number} y - Y position of this tile.
- * @param {number} index - The index of this tile type in the core map data.
+ * Puts a tile of the given index value at the coordinate specified.
+ * @method Phaser.Tilemap#putTile
+ * @param {number} index - The index of this tile to set.
+ * @param {number} x - X position to place the tile (given in tile units, not pixels)
+ * @param {number} y - Y position to place the tile (given in tile units, not pixels)
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
putTile: function (index, x, y, layer) {
@@ -123,6 +193,14 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Gets a tile from the Tilemap Layer. The coordinates are given in tile values.
+ * @method Phaser.Tilemap#getTile
+ * @param {number} x - X position to get the tile from (given in tile units, not pixels)
+ * @param {number} y - Y position to get the tile from (given in tile units, not pixels)
+ * @param {number} [layer] - The Tilemap Layer to operate on.
+ * @return {number} The index of the tile at the given coordinates.
+ */
getTile: function (x, y, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
@@ -134,6 +212,14 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Gets a tile from the Tilemap layer. The coordinates are given in pixel values.
+ * @method Phaser.Tilemap#getTileWorldXY
+ * @param {number} x - X position to get the tile from (given in pixels)
+ * @param {number} y - Y position to get the tile from (given in pixels)
+ * @param {number} [layer] - The Tilemap Layer to operate on.
+ * @return {number} The index of the tile at the given coordinates.
+ */
getTileWorldXY: function (x, y, tileWidth, tileHeight, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
@@ -149,14 +235,19 @@ Phaser.Tilemap.prototype = {
},
/**
- * Set a specific tile with its x and y in tiles.
- * @method putTileWorldXY
- * @param {number} x - X position of this tile in world coordinates.
- * @param {number} y - Y position of this tile in world coordinates.
- * @param {number} index - The index of this tile type in the core map data.
+ * Puts a tile into the Tilemap layer. The coordinates are given in pixel values.
+ * @method Phaser.Tilemap#putTileWorldXY
+ * @param {number} index - The index of the tile to put into the layer.
+ * @param {number} x - X position to insert the tile (given in pixels)
+ * @param {number} y - Y position to insert the tile (given in pixels)
+ * @param {number} tileWidth - The width of the tile in pixels.
+ * @param {number} tileHeight - The height of the tile in pixels.
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
putTileWorldXY: function (index, x, y, tileWidth, tileHeight, layer) {
+ if (typeof layer === "undefined") { layer = this.currentLayer; }
+
x = this.game.math.snapToFloor(x, tileWidth) / tileWidth;
y = this.game.math.snapToFloor(y, tileHeight) / tileHeight;
@@ -169,7 +260,16 @@ Phaser.Tilemap.prototype = {
},
- // Values are in TILEs, not pixels.
+ /**
+ * Copies all of the tiles in the given rectangular block into the tilemap data buffer.
+ * @method Phaser.Tilemap#copy
+ * @param {number} x - X position of the top left of the area to copy (given in tiles, not pixels)
+ * @param {number} y - Y position of the top left of the area to copy (given in tiles, not pixels)
+ * @param {number} width - The width of the area to copy (given in tiles, not pixels)
+ * @param {number} height - The height of the area to copy (given in tiles, not pixels)
+ * @param {number} [layer] - The Tilemap Layer to operate on.
+ * @return {array} An array of the tiles that were copied.
+ */
copy: function (x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
@@ -221,6 +321,14 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Pastes a previously copied block of tile data into the given x/y coordinates. Data should have been prepared with Tilemap.copy.
+ * @method Phaser.Tilemap#paste
+ * @param {number} x - X position of the top left of the area to paste to (given in tiles, not pixels)
+ * @param {number} y - Y position of the top left of the area to paste to (given in tiles, not pixels)
+ * @param {array} tileblock - The block of tiles to paste.
+ * @param {number} layer - The Tilemap Layer to operate on.
+ */
paste: function (x, y, tileblock, layer) {
if (typeof x === "undefined") { x = 0; }
@@ -247,13 +355,13 @@ Phaser.Tilemap.prototype = {
/**
* Swap tiles with 2 kinds of indexes.
- * @method swapTile
+ * @method Phaser.Tilemap#swapTile
* @param {number} tileA - First tile index.
* @param {number} tileB - Second tile index.
- * @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
- * @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
- * @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles.
- * @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles.
+ * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} width - The width in tiles of the area to operate on.
+ * @param {number} height - The height in tiles of the area to operate on.
*/
swap: function (tileA, tileB, x, y, width, height, layer) {
@@ -273,6 +381,12 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Internal function that handles the swapping of tiles.
+ * @method Phaser.Tilemap#swapHandler
+ * @param {number} value
+ * @param {number} index
+ */
swapHandler: function (value, index) {
if (value.index === this._tempA)
@@ -287,14 +401,15 @@ Phaser.Tilemap.prototype = {
},
/**
- * Swap tiles with 2 kinds of indexes.
- * @method swapTile
- * @param {number} tileA - First tile index.
- * @param {number} tileB - Second tile index.
- * @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
- * @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
- * @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles.
- * @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles.
+ * For each tile in the given area (defined by x/y and width/height) run the given callback.
+ * @method Phaser.Tilemap#forEach
+ * @param {number} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
+ * @param {number} context - The context under which the callback should be run.
+ * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} width - The width in tiles of the area to operate on.
+ * @param {number} height - The height in tiles of the area to operate on.
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
forEach: function (callback, context, x, y, width, height, layer) {
@@ -312,14 +427,15 @@ Phaser.Tilemap.prototype = {
},
/**
- * Replaces one type of tile with another.
- * @method replace
+ * Replaces one type of tile with another in the given area (defined by x/y and width/height).
+ * @method Phaser.Tilemap#replace
* @param {number} tileA - First tile index.
* @param {number} tileB - Second tile index.
- * @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
- * @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
- * @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles.
- * @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles.
+ * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} width - The width in tiles of the area to operate on.
+ * @param {number} height - The height in tiles of the area to operate on.
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
replace: function (tileA, tileB, x, y, width, height, layer) {
@@ -343,14 +459,15 @@ Phaser.Tilemap.prototype = {
},
/**
- * Randomises a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed!
- * @method random
+ * Randomises a set of tiles in a given area.
+ * @method Phaser.Tilemap#random
* @param {number} tileA - First tile index.
* @param {number} tileB - Second tile index.
- * @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
- * @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
- * @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles.
- * @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles.
+ * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} width - The width in tiles of the area to operate on.
+ * @param {number} height - The height in tiles of the area to operate on.
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
random: function (x, y, width, height, layer) {
@@ -385,14 +502,15 @@ Phaser.Tilemap.prototype = {
},
/**
- * Randomises a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed!
- * @method random
+ * Shuffles a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed!
+ * @method Phaser.Tilemap#shuffle
* @param {number} tileA - First tile index.
* @param {number} tileB - Second tile index.
- * @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
- * @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
- * @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles.
- * @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles.
+ * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} width - The width in tiles of the area to operate on.
+ * @param {number} height - The height in tiles of the area to operate on.
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
shuffle: function (x, y, width, height, layer) {
@@ -416,13 +534,14 @@ Phaser.Tilemap.prototype = {
},
/**
- * Fill a tile block with a specific tile index.
- * @method fill
+ * Fill a block with a specific tile index.
+ * @method Phaser.Tilemap#fill
* @param {number} index - Index of tiles you want to fill with.
- * @param {number} [x] - X position (in tiles) of block's left-top corner.
- * @param {number} [y] - Y position (in tiles) of block's left-top corner.
- * @param {number} [width] - width of block.
- * @param {number} [height] - height of block.
+ * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
+ * @param {number} width - The width in tiles of the area to operate on.
+ * @param {number} height - The height in tiles of the area to operate on.
+ * @param {number} [layer] - The Tilemap Layer to operate on.
*/
fill: function (index, x, y, width, height, layer) {
@@ -442,6 +561,10 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Removes all layers from this tile map.
+ * @method Phaser.Tilemap#removeAllLayers
+ */
removeAllLayers: function () {
this.layers.length = 0;
@@ -449,6 +572,10 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Dumps the tilemap data out to the console.
+ * @method Phaser.Tilemap#dump
+ */
dump: function () {
var txt = '';
@@ -485,6 +612,10 @@ Phaser.Tilemap.prototype = {
},
+ /**
+ * Removes all layers from this tile map and nulls the game reference.
+ * @method Phaser.Tilemap#destroy
+ */
destroy: function () {
this.removeAllLayers();
diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js
index 61c85357..5099bcd9 100644
--- a/src/tilemap/TilemapLayer.js
+++ b/src/tilemap/TilemapLayer.js
@@ -1,69 +1,115 @@
-// Maybe should extend Sprite?
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* A Tilemap Layer is a set of map data combined with a Tileset in order to render that data to the game.
+*
+* @class Phaser.TilemapLayer
+* @constructor
+* @param {Phaser.Game} game - Game reference to the currently running game.
+* @param {number} x - The x coordinate of this layer.
+* @param {number} y - The y coordinate of this layer.
+* @param {number} renderWidth - Width of the layer.
+* @param {number} renderHeight - Height of the layer.
+* @param {Phaser.Tileset|string} tileset - The tile set used for rendering.
+* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs.
+* @param {number} layer - The layer index within the map.
+*/
Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) {
/**
- * @property {Phaser.Game} game - Description.
+ * @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
- * @property {Description} canvas - Description.
- * @default
+ * @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
*/
this.canvas = Phaser.Canvas.create(renderWidth, renderHeight);
/**
- * @property {Description} context - Description.
- * @default
+ * @property {CanvasRenderingContext2D} context - The 2d context of the canvas.
*/
this.context = this.canvas.getContext('2d');
/**
- * @property {Description} baseTexture - Description.
- * @default
+ * @property {PIXI.BaseTexture} baseTexture - Required Pixi var.
*/
this.baseTexture = new PIXI.BaseTexture(this.canvas);
/**
- * @property {Description} texture - Description.
- * @default
+ * @property {PIXI.Texture} texture - Required Pixi var.
*/
this.texture = new PIXI.Texture(this.baseTexture);
+ /**
+ * @property {Phaser.Frame} textureFrame - Dimensions of the renderable area.
+ */
this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemaplayer', game.rnd.uuid());
Phaser.Sprite.call(this, this.game, x, y, this.texture, this.textureFrame);
+ /**
+ * @property {number} type - The const type of this object.
+ * @default
+ */
this.type = Phaser.TILEMAPLAYER;
+ /**
+ * A layer that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
+ * @property {boolean} fixedToCamera - Fixes this layer to the Camera.
+ * @default
+ */
this.fixedToCamera = true;
/**
- * @property {Description} tileset - Description.
+ * @property {Phaser.Tileset} tileset - The tile set used for rendering.
*/
this.tileset = null;
+ /**
+ * @property {number} tileWidth - The width of a single tile in pixels.
+ */
this.tileWidth = 0;
+
+ /**
+ * @property {number} tileHeight - The height of a single tile in pixels.
+ */
this.tileHeight = 0;
+
+ /**
+ * @property {number} tileMargin - The margin around the tiles.
+ */
this.tileMargin = 0;
+
+ /**
+ * @property {number} tileSpacing - The spacing around the tiles.
+ */
this.tileSpacing = 0;
/**
- * Read-only variable, do NOT recommend changing after the map is loaded!
- * @property {number} widthInPixels
- * @default
+ * @property {number} widthInPixels - Do NOT recommend changing after the map is loaded!
+ * @readonly
*/
this.widthInPixels = 0;
/**
- * Read-only variable, do NOT recommend changing after the map is loaded!
- * @property {number} heightInPixels
- * @default
+ * @property {number} heightInPixels - Do NOT recommend changing after the map is loaded!
+ * @readonly
*/
this.heightInPixels = 0;
-
+ /**
+ * @property {number} renderWidth - The width of the area being rendered.
+ */
this.renderWidth = renderWidth;
+
+ /**
+ * @property {number} renderHeight - The height of the area being rendered.
+ */
this.renderHeight = renderHeight;
/**
@@ -108,9 +154,16 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
*/
this._ty = 0;
- this._results = [];
-
+ /**
+ * @property {number} _tw - Local render loop var to help avoid gc spikes.
+ * @private
+ */
this._tw = 0;
+
+ /**
+ * @property {number} _th - Local render loop var to help avoid gc spikes.
+ * @private
+ */
this._th = 0;
/**
@@ -143,6 +196,36 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
*/
this._startY = 0;
+ /**
+ * @property {array} _results - Local render loop var to help avoid gc spikes.
+ * @private
+ */
+ this._results = [];
+
+ /**
+ * @property {number} _x - Private var.
+ * @private
+ */
+ this._x = 0;
+
+ /**
+ * @property {number} _y - Private var.
+ * @private
+ */
+ this._y = 0;
+
+ /**
+ * @property {number} _prevX - Private var.
+ * @private
+ */
+ this._prevX = 0;
+
+ /**
+ * @property {number} _prevY - Private var.
+ * @private
+ */
+ this._prevY = 0;
+
/**
* @property {number} scrollFactorX - speed at which this layer scrolls
* horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls
@@ -150,6 +233,7 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
* @default 1
*/
this.scrollFactorX = 1;
+
/**
* @property {number} scrollFactorY - speed at which this layer scrolls
* vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls
@@ -158,15 +242,24 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
*/
this.scrollFactorY = 1;
+ /**
+ * @property {Phaser.Tilemap} tilemap - The Tilemap to which this layer is bound.
+ */
this.tilemap = null;
+
+ /**
+ * @property {number} layer - Tilemap layer index.
+ */
this.layer = null;
+
+ /**
+ * @property {number} index
+ */
this.index = 0;
- this._x = 0;
- this._y = 0;
- this._prevX = 0;
- this._prevY = 0;
-
+ /**
+ * @property {boolean} dirty - Flag controlling when to re-render the layer.
+ */
this.dirty = true;
if (tileset instanceof Phaser.Tileset || typeof tileset === 'string')
@@ -185,7 +278,12 @@ Phaser.TilemapLayer.prototype = Object.create(Phaser.Sprite.prototype);
Phaser.TilemapLayer.prototype = Phaser.Utils.extend(true, Phaser.TilemapLayer.prototype, Phaser.Sprite.prototype, PIXI.Sprite.prototype);
Phaser.TilemapLayer.prototype.constructor = Phaser.TilemapLayer;
-
+/**
+* Automatically called by World.preUpdate. Handles cache updates.
+*
+* @method Phaser.TilemapLayer#update
+* @memberof Phaser.TilemapLayer
+*/
Phaser.TilemapLayer.prototype.update = function () {
this.scrollX = this.game.camera.x * this.scrollFactorX;
@@ -195,12 +293,25 @@ Phaser.TilemapLayer.prototype.update = function () {
}
+/**
+* Sets the world size to match the size of this layer.
+*
+* @method Phaser.TilemapLayer#resizeWorld
+* @memberof Phaser.TilemapLayer
+*/
Phaser.TilemapLayer.prototype.resizeWorld = function () {
this.game.world.setBounds(0, 0, this.widthInPixels, this.heightInPixels);
}
+/**
+* Updates the Tileset data.
+*
+* @method Phaser.TilemapLayer#updateTileset
+* @memberof Phaser.TilemapLayer
+* @param {Phaser.Tileset|string} tileset - The tileset to use for this layer.
+*/
Phaser.TilemapLayer.prototype.updateTileset = function (tileset) {
if (tileset instanceof Phaser.Tileset)
@@ -225,6 +336,14 @@ Phaser.TilemapLayer.prototype.updateTileset = function (tileset) {
}
+/**
+* Updates the Tilemap data.
+*
+* @method Phaser.TilemapLayer#updateMapData
+* @memberof Phaser.TilemapLayer
+* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs.
+* @param {number} layer - The layer index within the map.
+*/
Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) {
if (typeof layer === 'undefined')
@@ -244,11 +363,14 @@ Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) {
}
/**
- * Take an x coordinate that doesn't account for scrollFactorY and 'fix' it
- * into a scrolled local space. Used primarily internally
- * @param {number} x - x coordinate in camera space
- * @return {number} x coordinate in scrollFactor-adjusted dimensions
- */
+* Take an x coordinate that doesn't account for scrollFactorY and 'fix' it
+* into a scrolled local space. Used primarily internally
+* @method Phaser.TilemapLayer#_fixX
+* @memberof Phaser.TilemapLayer
+* @private
+* @param {number} x - x coordinate in camera space
+* @return {number} x coordinate in scrollFactor-adjusted dimensions
+*/
Phaser.TilemapLayer.prototype._fixX = function(x) {
if (this.scrollFactorX === 1)
@@ -263,11 +385,14 @@ Phaser.TilemapLayer.prototype._fixX = function(x) {
}
/**
- * Take an x coordinate that _does_ account for scrollFactorY and 'unfix' it
- * back to camera space. Used primarily internally
- * @param {number} x - x coordinate in scrollFactor-adjusted dimensions
- * @return {number} x coordinate in camera space
- */
+* Take an x coordinate that _does_ account for scrollFactorY and 'unfix' it
+* back to camera space. Used primarily internally
+* @method Phaser.TilemapLayer#_unfixX
+* @memberof Phaser.TilemapLayer
+* @private
+* @param {number} x - x coordinate in scrollFactor-adjusted dimensions
+* @return {number} x coordinate in camera space
+*/
Phaser.TilemapLayer.prototype._unfixX = function(x) {
if (this.scrollFactorX === 1)
@@ -282,11 +407,14 @@ Phaser.TilemapLayer.prototype._unfixX = function(x) {
}
/**
- * Take a y coordinate that doesn't account for scrollFactorY and 'fix' it
- * into a scrolled local space. Used primarily internally
- * @param {number} y - y coordinate in camera space
- * @return {number} y coordinate in scrollFactor-adjusted dimensions
- */
+* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it
+* into a scrolled local space. Used primarily internally
+* @method Phaser.TilemapLayer#_fixY
+* @memberof Phaser.TilemapLayer
+* @private
+* @param {number} y - y coordinate in camera space
+* @return {number} y coordinate in scrollFactor-adjusted dimensions
+*/
Phaser.TilemapLayer.prototype._fixY = function(y) {
if (this.scrollFactorY === 1)
@@ -301,11 +429,14 @@ Phaser.TilemapLayer.prototype._fixY = function(y) {
}
/**
- * Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it
- * back to camera space. Used primarily internally
- * @param {number} y - y coordinate in scrollFactor-adjusted dimensions
- * @return {number} y coordinate in camera space
- */
+* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it
+* back to camera space. Used primarily internally
+* @method Phaser.TilemapLayer#_unfixY
+* @memberof Phaser.TilemapLayer
+* @private
+* @param {number} y - y coordinate in scrollFactor-adjusted dimensions
+* @return {number} y coordinate in camera space
+*/
Phaser.TilemapLayer.prototype._unfixY = function(y) {
if (this.scrollFactorY === 1)
@@ -321,9 +452,10 @@ Phaser.TilemapLayer.prototype._unfixY = function(y) {
/**
* Convert a pixel value to a tile coordinate.
+* @method Phaser.TilemapLayer#getTileX
+* @memberof Phaser.TilemapLayer
* @param {number} x - X position of the point in target tile.
-* @param {number} [layer] - layer of this tile located.
-* @return {number} The tile with specific properties.
+* @return {Phaser.Tile} The tile with specific properties.
*/
Phaser.TilemapLayer.prototype.getTileX = function (x) {
@@ -335,9 +467,10 @@ Phaser.TilemapLayer.prototype.getTileX = function (x) {
/**
* Convert a pixel value to a tile coordinate.
-* @param {number} x - X position of the point in target tile.
-* @param {number} [layer] - layer of this tile located.
-* @return {number} The tile with specific properties.
+* @method Phaser.TilemapLayer#getTileY
+* @memberof Phaser.TilemapLayer
+* @param {number} y - Y position of the point in target tile.
+* @return {Phaser.Tile} The tile with specific properties.
*/
Phaser.TilemapLayer.prototype.getTileY = function (y) {
@@ -347,6 +480,14 @@ Phaser.TilemapLayer.prototype.getTileY = function (y) {
}
+/**
+* Convert a pixel value to a tile coordinate.
+* @method Phaser.TilemapLayer#getTileXY
+* @memberof Phaser.TilemapLayer
+* @param {number} x - X position of the point in target tile.
+* @param {number} y - Y position of the point in target tile.
+* @return {Phaser.Tile} The tile with specific properties.
+*/
Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) {
point.x = this.getTileX(x);
@@ -357,9 +498,14 @@ Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) {
}
/**
-*
-* @method getTileOverlaps
-* @param {GameObject} object - Tiles you want to get that overlaps this.
+* Get the tiles within the given area.
+* @method Phaser.TilemapLayer#getTiles
+* @memberof Phaser.TilemapLayer
+* @param {number} x - X position of the top left of the area to copy (given in tiles, not pixels)
+* @param {number} y - Y position of the top left of the area to copy (given in tiles, not pixels)
+* @param {number} width - The width of the area to copy (given in tiles, not pixels)
+* @param {number} height - The height of the area to copy (given in tiles, not pixels)
+* @param {boolean} collides - If true only return tiles that collide on one or more faces.
* @return {array} Array with tiles informations (each contains x, y, and the tile).
*/
Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides) {
@@ -448,6 +594,11 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
}
+/**
+* Internal function to update maximum values.
+* @method Phaser.TilemapLayer#updateMax
+* @memberof Phaser.TilemapLayer
+*/
Phaser.TilemapLayer.prototype.updateMax = function () {
this._maxX = this.game.math.ceil(this.canvas.width / this.tileWidth) + 1;
@@ -473,6 +624,11 @@ Phaser.TilemapLayer.prototype.updateMax = function () {
}
+/**
+* Renders the tiles to the layer canvas and pushes to the display.
+* @method Phaser.TilemapLayer#render
+* @memberof Phaser.TilemapLayer
+*/
Phaser.TilemapLayer.prototype.render = function () {
if (this.tilemap && this.tilemap.dirty)
@@ -545,22 +701,50 @@ Phaser.TilemapLayer.prototype.render = function () {
}
+/**
+* Returns the absolute delta x value.
+* @method Phaser.TilemapLayer#deltaAbsX
+* @memberof Phaser.TilemapLayer
+* @return {number} Absolute delta X value
+*/
Phaser.TilemapLayer.prototype.deltaAbsX = function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
}
+/**
+* Returns the absolute delta y value.
+* @method Phaser.TilemapLayer#deltaAbsY
+* @memberof Phaser.TilemapLayer
+* @return {number} Absolute delta Y value
+*/
Phaser.TilemapLayer.prototype.deltaAbsY = function () {
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
}
+/**
+* Returns the delta x value.
+* @method Phaser.TilemapLayer#deltaX
+* @memberof Phaser.TilemapLayer
+* @return {number} Delta X value
+*/
Phaser.TilemapLayer.prototype.deltaX = function () {
return this._dx - this._prevX;
}
+/**
+* Returns the delta y value.
+* @method Phaser.TilemapLayer#deltaY
+* @memberof Phaser.TilemapLayer
+* @return {number} Delta Y value
+*/
Phaser.TilemapLayer.prototype.deltaY = function () {
return this._dy - this._prevY;
}
+/**
+* @name Phaser.TilemapLayer#scrollX
+* @property {number} scrollX - Scrolls the map horizontally or returns the current x position.
+*/
Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
get: function () {
@@ -597,6 +781,10 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
});
+/**
+* @name Phaser.TilemapLayer#scrollY
+* @property {number} scrollY - Scrolls the map vertically or returns the current y position.
+*/
Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
get: function () {
diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js
index e3ddd83b..0278c21a 100644
--- a/src/tilemap/TilemapParser.js
+++ b/src/tilemap/TilemapParser.js
@@ -1,5 +1,28 @@
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+
+/**
+* Phaser.TilemapParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into a Tilemap.
+*
+* @class Phaser.TilemapParser
+*/
Phaser.TilemapParser = {
+ /**
+ * Creates a Tileset object.
+ * @method Phaser.TilemapParser.tileset
+ * @param {Phaser.Game} game - Game reference to the currently running game.
+ * @param {string} key
+ * @param {number} tileWidth
+ * @param {number} tileHeight
+ * @param {number} tileMax
+ * @param {number} tileMargin
+ * @param {number} tileSpacing
+ * @return {Phaser.Tileset} Generated Tileset object.
+ */
tileset: function (game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
// How big is our image?
@@ -63,6 +86,14 @@ Phaser.TilemapParser = {
},
+ /**
+ * Parse tileset data from the cache and creates a Tileset object.
+ * @method Phaser.TilemapParser.parse
+ * @param {Phaser.Game} game - Game reference to the currently running game.
+ * @param {object} data
+ * @param {string} format
+ * @return {Phaser.Tileset} Generated Tileset object.
+ */
parse: function (game, data, format) {
if (format === Phaser.Tilemap.CSV)
@@ -77,10 +108,10 @@ Phaser.TilemapParser = {
},
/**
- * Parse csv map data and generate tiles.
- *
- * @method Phaser.Tilemap.prototype.parseCSV
- * @param {string} data - CSV map data.
+ * Parses a CSV file into valid map data.
+ * @method Phaser.TilemapParser.parseCSV
+ * @param {string} data - The CSV file data.
+ * @return {object} Generated map data.
*/
parseCSV: function (data) {
@@ -114,11 +145,10 @@ Phaser.TilemapParser = {
},
/**
- * Parse JSON map data and generate tiles.
- *
- * @method Phaser.Tilemap.prototype.parseTiledJSON
- * @param {string} data - JSON map data.
- * @param {string} key - Asset key for tileset image.
+ * Parses a Tiled JSON file into valid map data.
+ * @method Phaser.TilemapParser.parseJSON
+ * @param {object} json- The Tiled JSON data.
+ * @return {object} Generated map data.
*/
parseTiledJSON: function (json) {
diff --git a/src/tilemap/Tileset.js b/src/tilemap/Tileset.js
index 36e332a0..1f25a15d 100644
--- a/src/tilemap/Tileset.js
+++ b/src/tilemap/Tileset.js
@@ -1,4 +1,21 @@
+/**
+* @author Richard Davey
+* @copyright 2013 Photon Storm Ltd.
+* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
+*/
+/**
+* A Tile set is a combination of an image containing the tiles and collision data per tile.
+*
+* @class Phaser.Tileset
+* @constructor
+* @param {Image} image - The Image object from the Cache.
+* @param {string} key - The key of the tileset in the cache.
+* @param {number} tileWidth - The width of the tile in pixels.
+* @param {number} tileHeight - The height of the tile in pixels.
+* @param {number} [tileMargin] - The margin around the tiles in the sheet.
+* @param {number} [tileSpacing] - The spacing between the tiles in the sheet.
+*/
Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSpacing) {
if (typeof tileMargin === "undefined") { tileMargin = 0; }
@@ -9,19 +26,46 @@ Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSp
*/
this.key = key;
+ /**
+ * @property {object} image - The image used for rendering.
+ */
this.image = image;
+ /**
+ * @property {number} tileWidth - The width of a tile in pixels.
+ */
this.tileWidth = tileWidth;
+
+ /**
+ * @property {number} tileHeight - The height of a tile in pixels.
+ */
this.tileHeight = tileHeight;
+
+ /**
+ * @property {number} tileMargin - The margin around the tiles in the sheet.
+ */
this.margin = tileMargin;
+
+ /**
+ * @property {number} tileSpacing - The margin around the tiles in the sheet.
+ */
this.spacing = tileSpacing;
+ /**
+ * @property {array} tiles - An array of the tile collision data.
+ */
this.tiles = [];
}
Phaser.Tileset.prototype = {
+ /**
+ * Adds a Tile into this set.
+ *
+ * @method Phaser.Tileset#addTile
+ * @param {Phaser.Tile} tile - The tile to add to this set.
+ */
addTile: function (tile) {
this.tiles.push(tile);
@@ -30,6 +74,13 @@ Phaser.Tileset.prototype = {
},
+ /**
+ * Gets a Tile from this set.
+ *
+ * @method Phaser.Tileset#getTile
+ * @param {number} index - The index of the tile within the set.
+ * @return {Phaser.Tile} The tile.
+ */
getTile: function (index) {
if (this.tiles[index])
@@ -41,6 +92,13 @@ Phaser.Tileset.prototype = {
},
+ /**
+ * Sets tile spacing and margins.
+ *
+ * @method Phaser.Tileset#setSpacing
+ * @param {number} [tileMargin] - The margin around the tiles in the sheet.
+ * @param {number} [tileSpacing] - The spacing between the tiles in the sheet.
+ */
setSpacing: function (margin, spacing) {
this.tileMargin = margin;
@@ -48,6 +106,13 @@ Phaser.Tileset.prototype = {
},
+ /**
+ * Checks if the tile at the given index can collide.
+ *
+ * @method Phaser.Tileset#canCollide
+ * @param {number} index - The index of the tile within the set.
+ * @return {boolean} True or false depending on the tile collision or null if no tile was found at the given index.
+ */
canCollide: function (index) {
if (this.tiles[index])
@@ -59,12 +124,30 @@ Phaser.Tileset.prototype = {
},
+ /**
+ * Checks if the tile at the given index exists.
+ *
+ * @method Phaser.Tileset#checkTileIndex
+ * @param {number} index - The index of the tile within the set.
+ * @return {boolean} True if a tile exists at the given index otherwise false.
+ */
checkTileIndex: function (index) {
return (this.tiles[index]);
},
+ /**
+ * Sets collision values on a range of tiles in the set.
+ *
+ * @method Phaser.Tileset#setCollisionRange
+ * @param {number} start - The index to start setting the collision data on.
+ * @param {number} stop - The index to stop setting the collision data on.
+ * @param {boolean} left - Should the tile collide on the left?
+ * @param {boolean} right - Should the tile collide on the right?
+ * @param {boolean} up - Should the tile collide on the top?
+ * @param {boolean} down - Should the tile collide on the bottom?
+ */
setCollisionRange: function (start, stop, left, right, up, down) {
if (this.tiles[start] && this.tiles[stop] && start < stop)
@@ -77,6 +160,16 @@ Phaser.Tileset.prototype = {
},
+ /**
+ * Sets collision values on a tile in the set.
+ *
+ * @method Phaser.Tileset#setCollision
+ * @param {number} index - The index of the tile within the set.
+ * @param {boolean} left - Should the tile collide on the left?
+ * @param {boolean} right - Should the tile collide on the right?
+ * @param {boolean} up - Should the tile collide on the top?
+ * @param {boolean} down - Should the tile collide on the bottom?
+ */
setCollision: function (index, left, right, up, down) {
if (this.tiles[index])