diff --git a/Gruntfile.js b/Gruntfile.js
index c91d5950c..fa13b88a3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -153,6 +153,7 @@ module.exports = function (grunt) {
'src/math/Math.js',
'src/math/RandomDataGenerator.js',
+ 'src/math/QuadTree.js',
'src/net/Net.js',
@@ -184,7 +185,6 @@ module.exports = function (grunt) {
'src/physics/arcade/World.js',
'src/physics/arcade/Body.js',
- 'src/physics/arcade/QuadTree.js',
'src/physics/ninja/World.js',
'src/physics/ninja/Body.js',
diff --git a/build/config.php b/build/config.php
index ae12bc0e9..aea27a63a 100644
--- a/build/config.php
+++ b/build/config.php
@@ -108,6 +108,7 @@
+
@@ -139,7 +140,6 @@
-
diff --git a/examples/_site/view_full.html b/examples/_site/view_full.html
index d2c47e47c..0959686ca 100644
--- a/examples/_site/view_full.html
+++ b/examples/_site/view_full.html
@@ -114,6 +114,7 @@
+
diff --git a/examples/_site/view_lite.html b/examples/_site/view_lite.html
index 397143704..c5331fe7c 100644
--- a/examples/_site/view_lite.html
+++ b/examples/_site/view_lite.html
@@ -114,6 +114,7 @@
+
@@ -145,7 +146,6 @@
-
diff --git a/examples/wip/tween swap.js b/examples/wip/tween swap.js
index 3ece0b924..2490036c8 100644
--- a/examples/wip/tween swap.js
+++ b/examples/wip/tween swap.js
@@ -17,7 +17,7 @@ function create() {
game.stage.backgroundColor = 0x3d4d3d;
mummy = game.add.sprite(0, 300, 'mummy', 5);
- mummy.scale.set(2);
+ // mummy.scale.set(2);
anim = mummy.animations.add('walk');
@@ -26,6 +26,7 @@ function create() {
// game.onPause.add(paused, this);
// game.onResume.add(resumed, this);
+ game.add.tween(mummy.scale).to({x:4,y:4}, 1000, Phaser.Easing.Linear.None, true);
t = game.add.tween(mummy).to({x:700}, 15000, Phaser.Easing.Linear.None, true);
t.onComplete.add(tweenOver, this);
diff --git a/src/physics/arcade/QuadTree.js b/src/math/QuadTree.js
similarity index 86%
rename from src/physics/arcade/QuadTree.js
rename to src/math/QuadTree.js
index 598aae463..3398d8326 100644
--- a/src/physics/arcade/QuadTree.js
+++ b/src/math/QuadTree.js
@@ -44,7 +44,7 @@
/**
* QuadTree Constructor
*
- * @class Phaser.Physics.Arcade.QuadTree
+ * @class Phaser.QuadTree
* @classdesc A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts. However I've tweaked
* it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result. Original version at https://github.com/timohausmann/quadtree-js/
* @constructor
@@ -57,7 +57,7 @@
* @param {number} maxLevels - Description.
* @param {number} level - Description.
*/
-Phaser.Physics.Arcade.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
+Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
this.physicsManager = physicsManager;
this.ID = physicsManager.quadTreeID;
@@ -83,28 +83,28 @@ Phaser.Physics.Arcade.QuadTree = function (physicsManager, x, y, width, height,
};
-Phaser.Physics.Arcade.QuadTree.prototype = {
+Phaser.QuadTree.prototype = {
/*
* Split the node into 4 subnodes
*
- * @method Phaser.Physics.Arcade.QuadTree#split
+ * @method Phaser.QuadTree#split
*/
split: function() {
this.level++;
// top right node
- this.nodes[0] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
+ this.nodes[0] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
// top left node
- this.nodes[1] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
+ this.nodes[1] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
// bottom left node
- this.nodes[2] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
+ this.nodes[2] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
// bottom right node
- this.nodes[3] = new Phaser.Physics.Arcade.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
+ this.nodes[3] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
},
@@ -113,7 +113,7 @@ Phaser.Physics.Arcade.QuadTree.prototype = {
* exceeds the capacity, it will split and add all
* objects to their corresponding subnodes.
*
- * @method Phaser.Physics.Arcade.QuadTree#insert
+ * @method Phaser.QuadTree#insert
* @param {object} body - Description.
*/
insert: function (body) {
@@ -165,7 +165,7 @@ Phaser.Physics.Arcade.QuadTree.prototype = {
/*
* Determine which node the object belongs to.
*
- * @method Phaser.Physics.Arcade.QuadTree#getIndex
+ * @method Phaser.QuadTree#getIndex
* @param {object} rect - Description.
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
*/
@@ -209,7 +209,7 @@ Phaser.Physics.Arcade.QuadTree.prototype = {
/*
* Return all objects that could collide with the given object.
*
- * @method Phaser.Physics.Arcade.QuadTree#retrieve
+ * @method Phaser.QuadTree#retrieve
* @param {object} rect - Description.
* @Return {array} - Array with all detected objects.
*/
@@ -245,7 +245,7 @@ Phaser.Physics.Arcade.QuadTree.prototype = {
/*
* Clear the quadtree.
- * @method Phaser.Physics.Arcade.QuadTree#clear
+ * @method Phaser.QuadTree#clear
*/
clear: function () {
diff --git a/src/physics/Physics.js b/src/physics/Physics.js
index 16a9b981b..e0a82822e 100644
--- a/src/physics/Physics.js
+++ b/src/physics/Physics.js
@@ -137,7 +137,7 @@ Phaser.Physics.prototype = {
*
* @method Phaser.Physics#enable
* @param {object|array} object - The game object to create the physics body on. Can also be an array of objects, a body will be created on every object in the array.
- * @param {number} [system=0] - The physics system that will be used to create the body. Defaults to Arcade Physics.
+ * @param {number} [system=Phaser.Physics.ARCADE] - The physics system that will be used to create the body. Defaults to Arcade Physics.
*/
enable: function (object, system) {
@@ -145,33 +145,40 @@ Phaser.Physics.prototype = {
var i = 1;
- if (Array.isArray(object))
+ if (object instanceof Phaser.Group)
{
- // Add to Group
- i = object.length;
+
}
else
{
- object = [object];
- }
-
- while (i--)
- {
- if (object[i].body === null)
+ if (Array.isArray(object))
{
- if (system === Phaser.Physics.ARCADE)
+ // Add to Group
+ i = object.length;
+ }
+ else
+ {
+ object = [object];
+ }
+
+ while (i--)
+ {
+ if (object[i].body === null)
{
- object[i].body = new Phaser.Physics.Arcade.Body(object[i]);
- }
- else if (system === Phaser.Physics.P2)
- {
- object[i].body = new Phaser.Physics.P2.Body(this.game, object[i], object[i].x, object[i].y, 1);
- object[i].anchor.set(0.5);
- }
- else if (system === Phaser.Physics.NINJA)
- {
- object[i].body = new Phaser.Physics.Ninja.Body(this.ninja, object[i]);
- object[i].anchor.set(0.5);
+ if (system === Phaser.Physics.ARCADE)
+ {
+ object[i].body = new Phaser.Physics.Arcade.Body(object[i]);
+ }
+ else if (system === Phaser.Physics.P2)
+ {
+ object[i].body = new Phaser.Physics.P2.Body(this.game, object[i], object[i].x, object[i].y, 1);
+ object[i].anchor.set(0.5);
+ }
+ else if (system === Phaser.Physics.NINJA)
+ {
+ object[i].body = new Phaser.Physics.Ninja.Body(this.ninja, object[i]);
+ object[i].anchor.set(0.5);
+ }
}
}
}
diff --git a/src/physics/arcade/World.js b/src/physics/arcade/World.js
index 8a90b7ea1..bf1c3447c 100644
--- a/src/physics/arcade/World.js
+++ b/src/physics/arcade/World.js
@@ -165,6 +165,64 @@ Phaser.Physics.Arcade.prototype.constructor = Phaser.Physics.Arcade;
Phaser.Physics.Arcade.prototype = {
+ /**
+ * This will create an Arcade Physics body on the given game object or array of game objects.
+ * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed.
+ *
+ * @method Phaser.Physics.Arcade#enable
+ * @param {object|array|Phaser.Group} object - The game object to create the physics body on. Can also be an array of objects, a body will be created on every object in the array that has a body parameter.
+ * @param {boolean} [children=true] - Should a body be created on all children of this object? If true it will propagate down the display list.
+ */
+ enable: function (object, children) {
+
+ if (typeof children === 'undefined') { children = true; }
+
+ var i = 1;
+
+ if (Array.isArray(object))
+ {
+ // Add to Group
+ i = object.length;
+ }
+ else
+ {
+ object = [object];
+ }
+
+ while (i--)
+ {
+ if (object[i] instanceof Phaser.Group)
+ {
+ object[i].forEach(this.enableBody, this, false, children);
+ }
+ else
+ {
+ this.enableBody(object[i]);
+ }
+ }
+
+ },
+
+ enableBody: function (object, children) {
+
+ if (object instanceof Phaser.Group)
+ {
+ this.enable(object, true, children);
+ return;
+ }
+
+ if (object.hasOwnProperty('body') && object.body === null)
+ {
+ object.body = new Phaser.Physics.Arcade.Body(object);
+ }
+
+ if (children && object.hasOwnProperty('children'))
+ {
+ object.children.forEach(this.enable, this);
+ }
+
+ },
+
/**
* Called automatically by a Physics body, it updates all motion related values on the Body.
*