mirror of
https://github.com/wassname/phaser.git
synced 2026-07-05 17:30:19 +08:00
The way the collision process callback works has changed significantly and now works as originally intended.
The World level quadtree is no longer created, they are now built and ripped down each time you collide a Group, this helps collision accuracy. Bodies are no longer added to a world quadtree, so have had all of their quadtree properties removed such as skipQuadtree, quadTreeIndex, etc. QuadTree.populate - you can pass it a Group and it'll automatically insert all of the children ready for inspection. Removed ArcadePhysics binding to the QuadTree, so it can now be used independantly of the physics system.
This commit is contained in:
@@ -56,6 +56,9 @@ Significant API changes:
|
||||
* Tween.onStartCallback and onCompleteCallback have been removed to avoid confusion. You should use the onStart, onLoop and onComplete events instead.
|
||||
* Button.forceOut default value has changed from true to false, so Buttons will revert to an Up state (if set) when pressed and released.
|
||||
* Body.drag has been removed. Please use the new Body.friction value instead (which is a number value, not a Point object)
|
||||
* The way the collision process callback works has changed significantly and now works as originally intended.
|
||||
* The World level quadtree is no longer created, they are now built and ripped down each time you collide a Group, this helps collision accuracy.
|
||||
* Bodies are no longer added to a world quadtree, so have had all of their quadtree properties removed such as skipQuadtree, quadTreeIndex, etc.
|
||||
|
||||
|
||||
New features:
|
||||
@@ -85,6 +88,7 @@ New features:
|
||||
* Body.speed - the current speed of the body.
|
||||
* Body.friction - This now replaces Body.drag and provides for a much smoother friction experience.
|
||||
* Body.sleeping - A Physics Body can now be set to 'go to sleep' if the velocity drops between the given range (sleepMin and sleepMax) for the given period of sleepDuration (see the new examples).
|
||||
* QuadTree.populate - you can pass it a Group and it'll automatically insert all of the children ready for inspection.
|
||||
|
||||
|
||||
New Examples:
|
||||
@@ -143,6 +147,7 @@ Updates:
|
||||
* Added StateManager.getCurrentState to return the currently running State object (thanks Niondir)
|
||||
* Removed the console.log redirect from Utils as it was messing with Firefox.
|
||||
* Body.acceleration is now much smoother and less eratic at high speeds.
|
||||
* Removed ArcadePhysics binding to the QuadTree, so it can now be used independantly of the physics system.
|
||||
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite1;
|
||||
var sprite2;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
// This will check Sprite vs. Sprite collision using a custom process callback
|
||||
sprite1 = game.add.sprite(0, 200, 'atari');
|
||||
sprite2 = game.add.sprite(750, 220, 'mushroom');
|
||||
|
||||
// We'll use random velocities so we can test it in our processCallback
|
||||
sprite1.body.velocity.x = 50 + Math.random() * 100;
|
||||
sprite2.body.velocity.x = -(50 + Math.random() * 100);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionCallback, processCallback, this);
|
||||
|
||||
}
|
||||
|
||||
function processCallback (obj1, obj2) {
|
||||
|
||||
// This function can perform your own additional checks on the 2 objects that collided.
|
||||
// For example you could test for velocity, health, etc.
|
||||
// This function needs to return either true or false. If it returns true then collision carries on (separating the two objects).
|
||||
// If it returns false the collision is assumed to have failed and aborts, no further checks or separation happen.
|
||||
|
||||
if (obj1.body.speed > obj2.body.speed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function collisionCallback (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderText('The processCallback will only collide if sprite1 is going fastest.', 32, 32);
|
||||
game.debug.renderText('Sprite 1 speed: ' + sprite1.body.speed, 32, 64);
|
||||
game.debug.renderText('Sprite 2 speed: ' + sprite2.body.speed, 32, 96);
|
||||
|
||||
}
|
||||
|
||||
@@ -84,6 +84,6 @@ function collisionHandler (obj1, obj2) {
|
||||
|
||||
function render () {
|
||||
|
||||
game.debug.renderQuadTree(game.physics.quadTree);
|
||||
// game.debug.renderQuadTree(game.physics.quadTree);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite1;
|
||||
var sprite2;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
// This will check Sprite vs. Sprite collision using a custom process callback
|
||||
|
||||
sprite1 = game.add.sprite(0, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
// We'll use a random velocity here so we can test it in our processHandler
|
||||
sprite1.body.velocity.x = 50 + Math.random() * 100;
|
||||
// This tells phaser to not use the built-in body separation, instead you should handle it in your process callback (see below)
|
||||
sprite1.body.customSeparateX = true;
|
||||
|
||||
sprite2 = game.add.sprite(750, 220, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
// We'll use a random velocity here so we can test it in our processHandler
|
||||
sprite2.body.velocity.x = -(50 + Math.random() * 100);
|
||||
// This tells phaser to not use the built-in body separation, instead you should handle it in your process callback (see below)
|
||||
sprite2.body.customSeparateX = true;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, processHandler, this);
|
||||
|
||||
}
|
||||
|
||||
function processHandler (obj1, obj2) {
|
||||
|
||||
// This function can perform your own additional checks on the 2 objects that collided.
|
||||
// For example you could test for velocity, health, etc.
|
||||
// If you want the collision to be deemed successful this function must return true.
|
||||
// In which case the collisionHandler will be called, otherwise it won't.
|
||||
|
||||
// Note: the objects will have already been separated by this point unless you have set
|
||||
// their customSeparateX/Y flags to true. If you do that it's up to you to handle separation.
|
||||
|
||||
// Whichever one is going fastest wins, the other dies :)
|
||||
if (obj1.body.velocity.x > Math.abs(obj2.body.velocity.x))
|
||||
{
|
||||
obj2.kill();
|
||||
obj1.body.velocity.x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj1.kill();
|
||||
obj2.body.velocity.x = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ function update() {
|
||||
|
||||
function collisionHandler (obj1, obj2) {
|
||||
|
||||
// The two sprites are colliding
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,14 +20,13 @@ function create() {
|
||||
sprite1.body.velocity.y = 100;
|
||||
|
||||
// This adjusts the collision body size.
|
||||
// 100x100 is the new width/height.
|
||||
// 220x10 is the new width/height.
|
||||
// See the offset bounding box for another example.
|
||||
sprite1.body.setSize(220, 50, 0, 0);
|
||||
sprite1.body.setSize(220, 10, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(400, 500, 'mushroom');
|
||||
sprite2 = game.add.sprite(400, 450, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
sprite2.body.immovable = true;
|
||||
// sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
@@ -42,17 +41,14 @@ function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
game.debug.renderSpriteCollision(sprite1, 400, 32);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -963,6 +963,7 @@ Phaser.Group.prototype = {
|
||||
* Allows you to call your own function on each member of this Group. You must pass the callback and context in which it will run.
|
||||
* After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
|
||||
* For example: Group.forEach(awardBonusGold, this, true, 100, 500)
|
||||
* Note: Currently this will skip any children which are Groups themselves.
|
||||
*
|
||||
* @method Phaser.Group#forEach
|
||||
* @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter.
|
||||
|
||||
+79
-59
@@ -5,18 +5,18 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Javascript QuadTree
|
||||
* @version 1.0
|
||||
* @author Timo Hausmann
|
||||
*
|
||||
* @version 1.2, September 4th 2013
|
||||
* @author Richard Davey
|
||||
* 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/
|
||||
*/
|
||||
* Javascript QuadTree
|
||||
* @version 1.0
|
||||
* @author Timo Hausmann
|
||||
*
|
||||
* @version 1.2, September 4th 2013
|
||||
* @author Richard Davey
|
||||
* 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/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @copyright © 2012 Timo Hausmann
|
||||
@@ -42,27 +42,23 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* QuadTree Constructor
|
||||
*
|
||||
* @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
|
||||
* @param {Description} physicsManager - Description.
|
||||
* @param {Description} x - Description.
|
||||
* @param {Description} y - Description.
|
||||
* @param {number} width - The width of your game in game pixels.
|
||||
* @param {number} height - The height of your game in game pixels.
|
||||
* @param {number} maxObjects - Description.
|
||||
* @param {number} maxLevels - Description.
|
||||
* @param {number} level - Description.
|
||||
*/
|
||||
Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
|
||||
* QuadTree Constructor
|
||||
*
|
||||
* @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
|
||||
* @param {number} x - The top left coordinate of the quadtree.
|
||||
* @param {number} y - The top left coordinate of the quadtree.
|
||||
* @param {number} width - The width of the quadtree in pixels.
|
||||
* @param {number} height - The height of the quadtree in pixels.
|
||||
* @param {number} [maxObjects=10] - The maximum number of objects per node.
|
||||
* @param {number} [maxLevels=4] - The maximum number of levels to iterate to.
|
||||
* @param {number} [level=0] - Which level is this?
|
||||
*/
|
||||
Phaser.QuadTree = function (x, y, width, height, maxObjects, maxLevels, level) {
|
||||
|
||||
this.physicsManager = physicsManager;
|
||||
this.ID = physicsManager.quadTreeID;
|
||||
physicsManager.quadTreeID++;
|
||||
|
||||
this.maxObjects = maxObjects || 10;
|
||||
this.maxLevels = maxLevels || 4;
|
||||
this.level = level || 0;
|
||||
@@ -86,35 +82,60 @@ Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, max
|
||||
Phaser.QuadTree.prototype = {
|
||||
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
* Populates this quadtree with the members of the given Group.
|
||||
*
|
||||
* @method Phaser.QuadTree#split
|
||||
* @method Phaser.QuadTree#populate
|
||||
* @param {Phaser.Group} group - The Group to add to the quadtree.
|
||||
*/
|
||||
split: function() {
|
||||
populate: function (group) {
|
||||
|
||||
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);
|
||||
group.forEach(this.populateHandler, this, true);
|
||||
|
||||
},
|
||||
|
||||
/*
|
||||
* Insert the object into the node. If the node
|
||||
* exceeds the capacity, it will split and add all
|
||||
* objects to their corresponding subnodes.
|
||||
* Handler for the populate method.
|
||||
*
|
||||
* @method Phaser.QuadTree#populateHandler
|
||||
* @param {Phaser.Sprite} sprite - The Sprite to check.
|
||||
*/
|
||||
populateHandler: function (sprite) {
|
||||
|
||||
if (sprite.body && sprite.body.allowCollision.none === false && sprite.alive)
|
||||
{
|
||||
this.insert(sprite.body);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
*
|
||||
* @method Phaser.QuadTree#split
|
||||
*/
|
||||
split: function () {
|
||||
|
||||
this.level++;
|
||||
|
||||
// top right node
|
||||
this.nodes[0] = new Phaser.QuadTree(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.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.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.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.
|
||||
* @param {Phaser.Physics.Arcade.Body|object} body - The Body object to insert into the quadtree.
|
||||
*/
|
||||
insert: function (body) {
|
||||
|
||||
@@ -166,7 +187,7 @@ Phaser.QuadTree.prototype = {
|
||||
* Determine which node the object belongs to.
|
||||
*
|
||||
* @method Phaser.QuadTree#getIndex
|
||||
* @param {object} rect - Description.
|
||||
* @param {Phaser.Rectangle|object} rect - The bounds in which to check.
|
||||
* @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) {
|
||||
@@ -206,12 +227,12 @@ Phaser.QuadTree.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/*
|
||||
* Return all objects that could collide with the given object.
|
||||
/*
|
||||
* Return all objects that could collide with the given Sprite.
|
||||
*
|
||||
* @method Phaser.QuadTree#retrieve
|
||||
* @param {object} rect - Description.
|
||||
* @Return {array} - Array with all detected objects.
|
||||
* @param {Phaser.Sprite} sprite - The sprite to check against.
|
||||
* @return {array} - Array with all detected objects.
|
||||
*/
|
||||
retrieve: function (sprite) {
|
||||
|
||||
@@ -220,7 +241,7 @@ Phaser.QuadTree.prototype = {
|
||||
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
||||
|
||||
// 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.quadTreeIDs.push(this.ID);
|
||||
|
||||
if (this.nodes[0])
|
||||
{
|
||||
@@ -253,7 +274,6 @@ Phaser.QuadTree.prototype = {
|
||||
|
||||
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();
|
||||
|
||||
+103
-451
@@ -230,14 +230,6 @@ Phaser.Physics.Arcade.prototype = {
|
||||
* @protected
|
||||
*/
|
||||
preUpdate: function () {
|
||||
|
||||
// Clear the tree
|
||||
this.quadTree.clear();
|
||||
|
||||
// Create our tree which all of the Physics bodies will add themselves to
|
||||
this.quadTreeID = 0;
|
||||
this.quadTree = new Phaser.QuadTree(this, this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -247,10 +239,6 @@ Phaser.Physics.Arcade.prototype = {
|
||||
* @protected
|
||||
*/
|
||||
postUpdate: function () {
|
||||
|
||||
// Clear the tree ready for the next update
|
||||
this.quadTree.clear();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -283,11 +271,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsSprite(object1, object2, overlapCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext, true);
|
||||
}
|
||||
else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object1, object2, overlapCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsGroup(object1, object2, overlapCallback, processCallback, callbackContext, true);
|
||||
}
|
||||
}
|
||||
// GROUPS
|
||||
@@ -295,11 +283,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext, true);
|
||||
}
|
||||
else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
|
||||
{
|
||||
this.overlapGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext);
|
||||
this.collideGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext, true);
|
||||
}
|
||||
}
|
||||
// EMITTER
|
||||
@@ -307,11 +295,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.overlapSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsGroup(object2, object1, overlapCallback, processCallback, callbackContext, true);
|
||||
}
|
||||
else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
|
||||
{
|
||||
this.overlapGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext);
|
||||
this.collideGroupVsGroup(object1, object2, overlapCallback, processCallback, callbackContext, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,116 +308,6 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks for collision between two game objects. You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions.
|
||||
* The objects are also automatically separated. If you don't require separation then use ArcadePhysics.overlap instead.
|
||||
@@ -462,11 +340,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsSprite(object1, object2, collideCallback, processCallback, callbackContext, false);
|
||||
}
|
||||
else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
|
||||
{
|
||||
this.collideSpriteVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsGroup(object1, object2, collideCallback, processCallback, callbackContext, false);
|
||||
}
|
||||
else if (object2.type == Phaser.TILEMAPLAYER)
|
||||
{
|
||||
@@ -478,11 +356,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext, false);
|
||||
}
|
||||
else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
|
||||
{
|
||||
this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext, false);
|
||||
}
|
||||
else if (object2.type == Phaser.TILEMAPLAYER)
|
||||
{
|
||||
@@ -506,11 +384,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (object2.type == Phaser.SPRITE || object2.type == Phaser.TILESPRITE)
|
||||
{
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext);
|
||||
this.collideSpriteVsGroup(object2, object1, collideCallback, processCallback, callbackContext, false);
|
||||
}
|
||||
else if (object2.type == Phaser.GROUP || object2.type == Phaser.EMITTER)
|
||||
{
|
||||
this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext);
|
||||
this.collideGroupVsGroup(object1, object2, collideCallback, processCallback, callbackContext, false);
|
||||
}
|
||||
else if (object2.type == Phaser.TILEMAPLAYER)
|
||||
{
|
||||
@@ -523,6 +401,94 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#collideSpriteVsSprite
|
||||
* @private
|
||||
*/
|
||||
collideSpriteVsSprite: function (sprite1, sprite2, collideCallback, processCallback, callbackContext, overlapOnly) {
|
||||
|
||||
if (this.separate(sprite1.body, sprite2.body, processCallback, callbackContext, overlapOnly))
|
||||
{
|
||||
if (collideCallback)
|
||||
{
|
||||
collideCallback.call(callbackContext, sprite1, sprite2);
|
||||
}
|
||||
|
||||
this._total++;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#collideSpriteVsGroup
|
||||
* @private
|
||||
*/
|
||||
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext, overlapOnly) {
|
||||
|
||||
if (group.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// What is the sprite colliding with in the quadtree?
|
||||
this.quadTree.clear();
|
||||
|
||||
this.quadTree = new Phaser.QuadTree(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height, this.maxObjects, this.maxLevels);
|
||||
|
||||
this.quadTree.populate(group);
|
||||
|
||||
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.separate(sprite.body, this._potentials[i], processCallback, callbackContext, overlapOnly))
|
||||
{
|
||||
if (collideCallback)
|
||||
{
|
||||
collideCallback.call(callbackContext, sprite, this._potentials[i].sprite);
|
||||
}
|
||||
|
||||
this._total++;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#collideGroupVsGroup
|
||||
* @private
|
||||
*/
|
||||
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext, overlapOnly) {
|
||||
|
||||
if (group1.length === 0 || group2.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (group1._container.first._iNext)
|
||||
{
|
||||
var currentNode = group1._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.exists)
|
||||
{
|
||||
this.collideSpriteVsGroup(currentNode, group2, collideCallback, processCallback, callbackContext, overlapOnly);
|
||||
}
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != group1._container.last._iNext);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
@@ -606,91 +572,6 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#collideSpriteVsSprite
|
||||
* @private
|
||||
*/
|
||||
collideSpriteVsSprite: function (sprite1, sprite2, collideCallback, processCallback, callbackContext) {
|
||||
|
||||
if (this.separate(sprite1.body, sprite2.body, processCallback, callbackContext))
|
||||
{
|
||||
if (collideCallback)
|
||||
{
|
||||
collideCallback.call(callbackContext, sprite1, sprite2);
|
||||
}
|
||||
|
||||
this._total++;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#collideSpriteVsGroup
|
||||
* @private
|
||||
*/
|
||||
collideSpriteVsGroup: function (sprite, group, collideCallback, 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)
|
||||
{
|
||||
if (this.separate(sprite1.body, this._potentials[i], processCallback, callbackContext))
|
||||
{
|
||||
if (collideCallback)
|
||||
{
|
||||
collideCallback.call(callbackContext, sprite1, sprite2);
|
||||
}
|
||||
|
||||
this._total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal function. Use Phaser.Physics.Arcade.collide instead.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#collideGroupVsGroup
|
||||
* @private
|
||||
*/
|
||||
collideGroupVsGroup: function (group1, group2, collideCallback, 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.collideSpriteVsGroup(currentNode, group2, collideCallback, processCallback, callbackContext);
|
||||
}
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != group1._container.last._iNext);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The core separation function to separate two physics bodies.
|
||||
* @method Phaser.Physics.Arcade#separate
|
||||
@@ -700,7 +581,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
* @param {object} [callbackContext] - The context in which to run the process callback.
|
||||
* @returns {boolean} Returns true if the bodies collided, otherwise false.
|
||||
*/
|
||||
separate: function (body1, body2, processCallback, callbackContext) {
|
||||
separate: function (body1, body2, processCallback, callbackContext, overlapOnly) {
|
||||
|
||||
// Can't separate two immovable bodies and the same body cannot collide with itself
|
||||
if (body1 === body2 || (body1.immovable && body2.immovable) || Phaser.Rectangle.intersects(body1, body2) === false)
|
||||
@@ -762,7 +643,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
body1.overlapX = this._overlap;
|
||||
body2.overlapX = this._overlap;
|
||||
|
||||
if (!body1.customSeparateX && !body2.customSeparateX)
|
||||
if (!overlapOnly && !body1.customSeparateX && !body2.customSeparateX)
|
||||
{
|
||||
this._velocity1 = body1.velocity.x;
|
||||
this._velocity2 = body2.velocity.x;
|
||||
@@ -846,7 +727,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
body1.overlapY = this._overlap;
|
||||
body2.overlapY = this._overlap;
|
||||
|
||||
if (!body1.customSeparateY && !body2.customSeparateY)
|
||||
if (!overlapOnly && !body1.customSeparateY && !body2.customSeparateY)
|
||||
{
|
||||
this._velocity1 = body1.velocity.y;
|
||||
this._velocity2 = body2.velocity.y;
|
||||
@@ -898,235 +779,6 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The core separation function to separate two physics bodies on the x axis.
|
||||
* @method Phaser.Physics.Arcade#separateX
|
||||
* @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
|
||||
* @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
|
||||
* @returns {boolean} Returns true if the bodies were separated, otherwise false.
|
||||
separateX: function (body1, body2) {
|
||||
|
||||
// Can't separate two immovable bodies
|
||||
if (body1.immovable && body2.immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._overlap = 0;
|
||||
|
||||
// Check if the hulls actually overlap
|
||||
if (Phaser.Rectangle.intersects(body1, body2))
|
||||
{
|
||||
this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS;
|
||||
|
||||
if (body1.deltaX() === 0 && body2.deltaX() === 0)
|
||||
{
|
||||
// They overlap but neither of them are moving
|
||||
body1.embedded = true;
|
||||
body2.embedded = true;
|
||||
}
|
||||
else if (body1.deltaX() > body2.deltaX())
|
||||
{
|
||||
// Body1 is moving right and/or Body2 is moving left
|
||||
this._overlap = body1.x + body1.width - body2.x;
|
||||
|
||||
if ((this._overlap > this._maxOverlap) || body1.allowCollision.right === false || body2.allowCollision.left === false)
|
||||
{
|
||||
this._overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body1.touching.right = true;
|
||||
body2.touching.left = true;
|
||||
}
|
||||
}
|
||||
else if (body1.deltaX() < body2.deltaX())
|
||||
{
|
||||
// Body1 is moving left and/or Body2 is moving right
|
||||
this._overlap = body1.x - body2.width - body2.x;
|
||||
|
||||
if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left === false || body2.allowCollision.right === false)
|
||||
{
|
||||
this._overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body1.touching.left = true;
|
||||
body2.touching.right = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap !== 0)
|
||||
{
|
||||
body1.overlapX = this._overlap;
|
||||
body2.overlapX = this._overlap;
|
||||
|
||||
if (body1.customSeparateX || body2.customSeparateX)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
this._velocity1 = body1.velocity.x;
|
||||
this._velocity2 = body2.velocity.x;
|
||||
|
||||
if (!body1.immovable && !body2.immovable)
|
||||
{
|
||||
this._overlap *= 0.5;
|
||||
|
||||
body1.x = body1.x - this._overlap;
|
||||
body2.x += this._overlap;
|
||||
|
||||
this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1);
|
||||
this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1);
|
||||
this._average = (this._newVelocity1 + this._newVelocity2) * 0.5;
|
||||
this._newVelocity1 -= this._average;
|
||||
this._newVelocity2 -= this._average;
|
||||
|
||||
body1.velocity.x = this._average + this._newVelocity1 * body1.bounce.x;
|
||||
body2.velocity.x = this._average + this._newVelocity2 * body2.bounce.x;
|
||||
}
|
||||
else if (!body1.immovable)
|
||||
{
|
||||
body1.x = body1.x - this._overlap;
|
||||
body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x;
|
||||
}
|
||||
else if (!body2.immovable)
|
||||
{
|
||||
body2.x += this._overlap;
|
||||
body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* The core separation function to separate two physics bodies on the y axis.
|
||||
* @method Phaser.Physics.Arcade#separateY
|
||||
* @param {Phaser.Physics.Arcade.Body} body1 - The Body object to separate.
|
||||
* @param {Phaser.Physics.Arcade.Body} body2 - The Body object to separate.
|
||||
* @returns {boolean} Returns true if the bodies were separated, otherwise false.
|
||||
separateY: function (body1, body2) {
|
||||
|
||||
// Can't separate two immovable or non-existing bodys
|
||||
if (body1.immovable && body2.immovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this._overlap = 0;
|
||||
|
||||
// Check if the hulls actually overlap
|
||||
if (Phaser.Rectangle.intersects(body1, body2))
|
||||
{
|
||||
this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS;
|
||||
|
||||
if (body1.deltaY() === 0 && body2.deltaY() === 0)
|
||||
{
|
||||
// They overlap but neither of them are moving
|
||||
body1.embedded = true;
|
||||
body2.embedded = true;
|
||||
}
|
||||
else if (body1.deltaY() > body2.deltaY())
|
||||
{
|
||||
// Body1 is moving down and/or Body2 is moving up
|
||||
this._overlap = body1.y + body1.height - body2.y;
|
||||
|
||||
if ((this._overlap > this._maxOverlap) || body1.allowCollision.down === false || body2.allowCollision.up === false)
|
||||
{
|
||||
this._overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body1.touching.down = true;
|
||||
body2.touching.up = true;
|
||||
}
|
||||
}
|
||||
else if (body1.deltaY() < body2.deltaY())
|
||||
{
|
||||
// Body1 is moving up and/or Body2 is moving down
|
||||
this._overlap = body1.y - body2.height - body2.y;
|
||||
|
||||
if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up === false || body2.allowCollision.down === false)
|
||||
{
|
||||
this._overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body1.touching.up = true;
|
||||
body2.touching.down = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap !== 0)
|
||||
{
|
||||
body1.overlapY = this._overlap;
|
||||
body2.overlapY = this._overlap;
|
||||
|
||||
if (body1.customSeparateY || body2.customSeparateY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
this._velocity1 = body1.velocity.y;
|
||||
this._velocity2 = body2.velocity.y;
|
||||
|
||||
if (!body1.immovable && !body2.immovable)
|
||||
{
|
||||
this._overlap *= 0.5;
|
||||
|
||||
body1.y = body1.y - this._overlap;
|
||||
body2.y += this._overlap;
|
||||
|
||||
this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1);
|
||||
this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1);
|
||||
this._average = (this._newVelocity1 + this._newVelocity2) * 0.5;
|
||||
this._newVelocity1 -= this._average;
|
||||
this._newVelocity2 -= this._average;
|
||||
|
||||
body1.velocity.y = this._average + this._newVelocity1 * body1.bounce.y;
|
||||
body2.velocity.y = this._average + this._newVelocity2 * body2.bounce.y;
|
||||
}
|
||||
else if (!body1.immovable)
|
||||
{
|
||||
body1.y -= this._overlap;
|
||||
body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y;
|
||||
|
||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||
if (body2.moves)
|
||||
{
|
||||
body1.x += body2.x - body2.preX;
|
||||
}
|
||||
}
|
||||
else if (!body2.immovable)
|
||||
{
|
||||
body2.y += this._overlap;
|
||||
body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y;
|
||||
|
||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||
if (body1.moves)
|
||||
{
|
||||
body2.x += body1.x - body1.preX;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* The core separation function to separate a physics body and an array of tiles.
|
||||
* @method Phaser.Physics.Arcade#separateTiles
|
||||
|
||||
+15
-35
@@ -141,14 +141,15 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
*/
|
||||
this.acceleration = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {number} speed - The speed in pixels per second sq. of the Body.
|
||||
*/
|
||||
this.speed = 0;
|
||||
this.angle = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} drag - The drag applied to the motion of the Body.
|
||||
* @property {number} angle - The angle of the Body in radians.
|
||||
*/
|
||||
this.drag = new Phaser.Point();
|
||||
this.angle = 0;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} gravity - The gravity applied to the motion of the Body.
|
||||
@@ -196,26 +197,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
*/
|
||||
this.mass = 1;
|
||||
|
||||
/**
|
||||
* @property {boolean} skipQuadTree - If the Body is an irregular shape you can set this to true to avoid it being added to the World quad tree.
|
||||
* @default
|
||||
*/
|
||||
this.skipQuadTree = false;
|
||||
|
||||
/**
|
||||
* @property {Array} quadTreeIDs - Internal ID cache.
|
||||
* @protected
|
||||
*/
|
||||
this.quadTreeIDs = [];
|
||||
|
||||
/**
|
||||
* @property {number} quadTreeIndex - Internal ID cache.
|
||||
* @protected
|
||||
*/
|
||||
this.quadTreeIndex = -1;
|
||||
|
||||
// Allow collision
|
||||
|
||||
/**
|
||||
* Set the allowCollision properties to control which directions collision is processed for this Body.
|
||||
* For example allowCollision.up = false means it won't collide when the collision happened while moving up.
|
||||
@@ -258,19 +239,19 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
this.moves = true;
|
||||
|
||||
/**
|
||||
* @property {number} rotation - The amount the Body is rotated.
|
||||
* @property {number} rotation - The amount the parent Sprite is rotated. Note: You cannot rotate an AABB.
|
||||
* @default
|
||||
*/
|
||||
this.rotation = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} allowRotation - Allow this Body to be rotated? (via angularVelocity, etc)
|
||||
* @property {boolean} allowRotation - Allow angular rotation? This will cause the Sprite to be rotated via angularVelocity, etc. Note that the AABB remains un-rotated.
|
||||
* @default
|
||||
*/
|
||||
this.allowRotation = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} allowGravity - Allow this Body to be influenced by the global Gravity?
|
||||
* @property {boolean} allowGravity - Allow this Body to be influenced by the global Gravity value? Note: It will always be influenced by the local gravity value.
|
||||
* @default
|
||||
*/
|
||||
this.allowGravity = true;
|
||||
@@ -308,7 +289,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
* @default
|
||||
*/
|
||||
this.sleeping = false;
|
||||
this.canSleep = true;
|
||||
this.canSleep = false;
|
||||
this.sleepMin = new Phaser.Point(-20, -20);
|
||||
this.sleepMax = new Phaser.Point(20, 20);
|
||||
this.sleepDuration = 2000; // ms
|
||||
@@ -436,17 +417,16 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
|
||||
{
|
||||
this.quadTreeIDs = [];
|
||||
this.quadTreeIndex = -1;
|
||||
this.game.physics.quadTree.insert(this);
|
||||
}
|
||||
|
||||
this.prevVelocity.copyFrom(this.velocity);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#applyMotion
|
||||
* @protected
|
||||
*/
|
||||
applyMotion: function () {
|
||||
|
||||
if (this.friction > 0 && this.acceleration.isZero())
|
||||
|
||||
+37
-10
@@ -683,7 +683,7 @@ Phaser.Utils.Debug.prototype = {
|
||||
* @param {Phaser.Sprite} sprite - Description.
|
||||
* @param {string} [color] - Color of the debug info to be rendered (format is css color string).
|
||||
*/
|
||||
renderSpriteBody: function (sprite, color) {
|
||||
renderSpriteTouching: function (sprite, color) {
|
||||
|
||||
if (this.context == null || sprite.body.touching.none === true)
|
||||
{
|
||||
@@ -733,6 +733,42 @@ Phaser.Utils.Debug.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders just the full Sprite bounds.
|
||||
* @method Phaser.Utils.Debug#renderSpriteBounds
|
||||
* @param {Phaser.Sprite} sprite - Description.
|
||||
* @param {string} [color] - Color of the debug info to be rendered (format is css color string).
|
||||
* @param {boolean} [fill=false] - If false the bounds outline is rendered, if true the whole rectangle is rendered.
|
||||
*/
|
||||
renderSpriteBody: function (sprite, color, fill) {
|
||||
|
||||
if (this.context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
color = color || 'rgb(255,0,255)';
|
||||
|
||||
if (typeof fill === 'undefined') { fill = false; }
|
||||
|
||||
this.start(0, 0, color);
|
||||
|
||||
if (fill)
|
||||
{
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.context.strokeStyle = color;
|
||||
this.context.strokeRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height);
|
||||
this.context.stroke();
|
||||
}
|
||||
|
||||
this.stop();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders just the full Sprite bounds.
|
||||
* @method Phaser.Utils.Debug#renderSpriteBounds
|
||||
@@ -762,16 +798,7 @@ Phaser.Utils.Debug.prototype = {
|
||||
{
|
||||
this.context.strokeStyle = color;
|
||||
this.context.strokeRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height);
|
||||
this.context.strokeRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height);
|
||||
// this.context.strokeRect(sprite.body.hull.x, sprite.body.hull.y, sprite.body.hull.width, sprite.body.hull.height);
|
||||
this.context.stroke();
|
||||
|
||||
// this.context.strokeStyle = '#ff0000';
|
||||
// this.context.strokeRect(sprite.body.hullX.x, sprite.body.hullX.y, sprite.body.hullX.width, sprite.body.hullX.height);
|
||||
// this.context.stroke();
|
||||
// this.context.strokeStyle = '#00ff00';
|
||||
// this.context.strokeRect(sprite.body.hullY.x, sprite.body.hullY.y, sprite.body.hullY.width, sprite.body.hullY.height);
|
||||
// this.context.stroke();
|
||||
}
|
||||
|
||||
this.stop();
|
||||
|
||||
Reference in New Issue
Block a user