mirror of
https://github.com/wassname/phaser.git
synced 2026-08-05 13:21:00 +08:00
Updated documentation.
This commit is contained in:
+226
-185
@@ -54,6 +54,10 @@
|
||||
<a href="Phaser.AnimationParser.html">AnimationParser</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapData.html">BitmapData</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapText.html">BitmapText</a>
|
||||
</li>
|
||||
@@ -138,6 +142,10 @@
|
||||
<a href="Phaser.Events.html">Events</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Filter.html">Filter</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Frame.html">Frame</a>
|
||||
</li>
|
||||
@@ -302,6 +310,26 @@
|
||||
<a href="Phaser.Text.html">Text</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tile.html">Tile</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tilemap.html">Tilemap</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TilemapParser.html">TilemapParser</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tileset.html">Tileset</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TileSprite.html">TileSprite</a>
|
||||
</li>
|
||||
@@ -310,6 +338,10 @@
|
||||
<a href="Phaser.Time.html">Time</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Timer.html">Timer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Touch.html">Touch</a>
|
||||
</li>
|
||||
@@ -356,6 +388,14 @@
|
||||
<a href="global.html#HEXtoRGB">HEXtoRGB</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#render">render</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#renderXY">renderXY</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#right">right</a>
|
||||
</li>
|
||||
@@ -441,208 +481,209 @@
|
||||
* @param {number} level - Description.
|
||||
*/
|
||||
Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
|
||||
|
||||
this.physicsManager = physicsManager;
|
||||
this.ID = physicsManager.quadTreeID;
|
||||
physicsManager.quadTreeID++;
|
||||
|
||||
this.physicsManager = physicsManager;
|
||||
this.ID = physicsManager.quadTreeID;
|
||||
physicsManager.quadTreeID++;
|
||||
|
||||
this.maxObjects = maxObjects || 10;
|
||||
this.maxLevels = maxLevels || 4;
|
||||
this.level = level || 0;
|
||||
this.maxObjects = maxObjects || 10;
|
||||
this.maxLevels = maxLevels || 4;
|
||||
this.level = level || 0;
|
||||
|
||||
this.bounds = {
|
||||
x: Math.round(x),
|
||||
y: Math.round(y),
|
||||
width: width,
|
||||
height: height,
|
||||
subWidth: Math.floor(width / 2),
|
||||
subHeight: Math.floor(height / 2),
|
||||
right: Math.round(x) + Math.floor(width / 2),
|
||||
bottom: Math.round(y) + Math.floor(height / 2)
|
||||
};
|
||||
|
||||
this.objects = [];
|
||||
this.nodes = [];
|
||||
this.bounds = {
|
||||
x: Math.round(x),
|
||||
y: Math.round(y),
|
||||
width: width,
|
||||
height: height,
|
||||
subWidth: Math.floor(width / 2),
|
||||
subHeight: Math.floor(height / 2),
|
||||
right: Math.round(x) + Math.floor(width / 2),
|
||||
bottom: Math.round(y) + Math.floor(height / 2)
|
||||
};
|
||||
|
||||
this.objects = [];
|
||||
this.nodes = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.QuadTree.prototype = {
|
||||
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
*
|
||||
* @method Phaser.QuadTree#split
|
||||
*/
|
||||
split: function() {
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
*
|
||||
* @method Phaser.QuadTree#split
|
||||
*/
|
||||
split: function() {
|
||||
|
||||
this.level++;
|
||||
|
||||
// top right node
|
||||
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.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.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.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
this.level++;
|
||||
|
||||
// top right node
|
||||
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.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.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.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/*
|
||||
* Insert the object into the node. If the node
|
||||
* exceeds the capacity, it will split and add all
|
||||
* objects to their corresponding subnodes.
|
||||
*
|
||||
* @method Phaser.QuadTree#insert
|
||||
* @param {object} body - Description.
|
||||
*/
|
||||
insert: function (body) {
|
||||
|
||||
var i = 0;
|
||||
var index;
|
||||
|
||||
// if we have subnodes ...
|
||||
if (this.nodes[0] != null)
|
||||
{
|
||||
index = this.getIndex(body);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this.nodes[index].insert(body);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.objects.push(body);
|
||||
|
||||
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
|
||||
{
|
||||
// Split if we don't already have subnodes
|
||||
if (this.nodes[0] == null)
|
||||
{
|
||||
this.split();
|
||||
}
|
||||
|
||||
// Add objects to subnodes
|
||||
while (i < this.objects.length)
|
||||
{
|
||||
index = this.getIndex(this.objects[i]);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
// this is expensive - see what we can do about it
|
||||
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Determine which node the object belongs to.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
getIndex: function (rect) {
|
||||
|
||||
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
|
||||
var index = -1;
|
||||
/*
|
||||
* Insert the object into the node. If the node
|
||||
* exceeds the capacity, it will split and add all
|
||||
* objects to their corresponding subnodes.
|
||||
*
|
||||
* @method Phaser.QuadTree#insert
|
||||
* @param {object} body - Description.
|
||||
*/
|
||||
insert: function (body) {
|
||||
|
||||
var i = 0;
|
||||
var index;
|
||||
|
||||
// if we have subnodes ...
|
||||
if (this.nodes[0] != null)
|
||||
{
|
||||
index = this.getIndex(body);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this.nodes[index].insert(body);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.objects.push(body);
|
||||
|
||||
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
|
||||
{
|
||||
// Split if we don't already have subnodes
|
||||
if (this.nodes[0] == null)
|
||||
{
|
||||
this.split();
|
||||
}
|
||||
|
||||
// Add objects to subnodes
|
||||
while (i < this.objects.length)
|
||||
{
|
||||
index = this.getIndex(this.objects[i]);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
// this is expensive - see what we can do about it
|
||||
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
|
||||
{
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-left quadrant of this quadtree
|
||||
index = 1;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-left quadrant of this quadtree
|
||||
index = 2;
|
||||
}
|
||||
}
|
||||
else if (rect.x > this.bounds.right)
|
||||
{
|
||||
// rect can completely fit within the right quadrants
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-right quadrant of this quadtree
|
||||
index = 0;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-right quadrant of this quadtree
|
||||
index = 3;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
},
|
||||
|
||||
/*
|
||||
* Determine which node the object belongs to.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
getIndex: function (rect) {
|
||||
|
||||
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
|
||||
var index = -1;
|
||||
|
||||
},
|
||||
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
|
||||
{
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-left quadrant of this quadtree
|
||||
index = 1;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-left quadrant of this quadtree
|
||||
index = 2;
|
||||
}
|
||||
}
|
||||
else if (rect.x > this.bounds.right)
|
||||
{
|
||||
// rect can completely fit within the right quadrants
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-right quadrant of this quadtree
|
||||
index = 0;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-right quadrant of this quadtree
|
||||
index = 3;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
|
||||
/*
|
||||
* Return all objects that could collide with the given object.
|
||||
*
|
||||
* @method Phaser.QuadTree#retrieve
|
||||
* @param {object} rect - Description.
|
||||
* @Return {array} - Array with all detected objects.
|
||||
*/
|
||||
retrieve: function (sprite) {
|
||||
|
||||
var returnObjects = this.objects;
|
||||
},
|
||||
|
||||
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
||||
/*
|
||||
* Return all objects that could collide with the given object.
|
||||
*
|
||||
* @method Phaser.QuadTree#retrieve
|
||||
* @param {object} rect - Description.
|
||||
* @Return {array} - Array with all detected objects.
|
||||
*/
|
||||
retrieve: function (sprite) {
|
||||
|
||||
var returnObjects = this.objects;
|
||||
|
||||
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
|
||||
sprite.body.quadTreeIDs.push(this.ID);
|
||||
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
||||
|
||||
if (this.nodes[0])
|
||||
{
|
||||
// if rect fits into a subnode ..
|
||||
if (sprite.body.quadTreeIndex !== -1)
|
||||
{
|
||||
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
|
||||
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
|
||||
}
|
||||
}
|
||||
|
||||
return returnObjects;
|
||||
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
|
||||
sprite.body.quadTreeIDs.push(this.ID);
|
||||
|
||||
},
|
||||
if (this.nodes[0])
|
||||
{
|
||||
// if rect fits into a subnode ..
|
||||
if (sprite.body.quadTreeIndex !== -1)
|
||||
{
|
||||
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
|
||||
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
|
||||
}
|
||||
}
|
||||
|
||||
return returnObjects;
|
||||
|
||||
/*
|
||||
* Clear the quadtree.
|
||||
* @method Phaser.QuadTree#clear
|
||||
*/
|
||||
clear: function () {
|
||||
|
||||
this.objects = [];
|
||||
|
||||
for (var i = 0, len = this.nodes.length; i < len; i++)
|
||||
{
|
||||
// if (typeof this.nodes[i] !== 'undefined')
|
||||
if (this.nodes[i])
|
||||
{
|
||||
this.nodes[i].clear();
|
||||
delete this.nodes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Clear the quadtree.
|
||||
* @method Phaser.QuadTree#clear
|
||||
*/
|
||||
clear: function () {
|
||||
|
||||
this.objects = [];
|
||||
|
||||
for (var i = 0, len = this.nodes.length; i < len; i++)
|
||||
{
|
||||
// if (typeof this.nodes[i] !== 'undefined')
|
||||
if (this.nodes[i])
|
||||
{
|
||||
this.nodes[i].clear();
|
||||
delete this.nodes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
</pre>
|
||||
@@ -666,7 +707,7 @@ Phaser.QuadTree.prototype = {
|
||||
|
||||
<span class="jsdoc-message">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
|
||||
on Thu Nov 07 2013 06:07:33 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
on Thu Nov 28 2013 15:56:25 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user