New Math functions added.

This commit is contained in:
photonstorm
2014-01-22 10:54:49 +00:00
parent 15a002e720
commit 7a0e9a478c
5 changed files with 607 additions and 79 deletions
+4
View File
@@ -93,6 +93,10 @@ New features:
* Input.setMoveCallback allows you to set a callback that will be fired each time the activePointer receives a DOM move event.
* Math.distancePow(x1,y1,x2,y2,power) returns the distance between two coordinates at the given power.
* Physics.collideArray(obj, array) for when you want to collide an object against a number of sprites that aren't all in the same Group.
* Math.reverseAngle - reverses an angle (in radians).
* Math.normalizeAngle - normalises an angle, now in radians only.
* Math.normalizeLatitude - Normalizes a latitude to the [-90,90] range.
* Math.normalizeLongitude - Normalizes a longitude to the [-180,180] range.
New Examples:
+97 -11
View File
@@ -15,6 +15,7 @@ var sprite;
var sprite2;
var sprite3;
var group;
var flag = false;
var bmd;
@@ -27,10 +28,94 @@ function create() {
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
test3();
test7();
}
function test7() {
game.physics.gravity.x = 200;
sprite = game.add.sprite(300, 300, 'gameboy', 0);
sprite.name = 'red';
sprite.body.collideWorldBounds = true;
sprite.body.bounce.setTo(0.8, 0.8);
// sprite.body.velocity.y = 100;
// sprite.body.gravity.y = 200;
// sprite.body.friction = 0.2;
game.input.onDown.add(launch7, this);
}
function launch7() {
sprite.body.velocity.x = -200;
sprite.body.velocity.y = 200;
}
function test6() {
game.physics.gravity.y = 100;
sprite = game.add.sprite(300, 200, 'gameboy', 0);
sprite.name = 'red';
sprite.body.collideWorldBounds = true;
sprite.body.bounce.setTo(0.5, 0.5);
game.input.onDown.add(launch6, this);
}
function launch6() {
sprite.body.velocity.x = 200;
sprite.body.velocity.y = -200;
}
function test5() {
sprite = game.add.sprite(0, 600, 'gameboy', 0);
sprite.name = 'red';
sprite.body.collideWorldBounds = true;
// sprite.body.bounce.setTo(0.9, 0.9);
game.input.onDown.add(launch5, this);
}
function launch5() {
sprite.body.velocity.x = 100;
sprite.body.velocity.y = -100;
game.time.events.add(Phaser.Timer.SECOND * 4, stop5, this);
}
function stop5() {
sprite.body.velocity.x = -100;
// sprite.body.velocity.y = 100;
console.log(sprite.x, sprite.body.x);
}
function test4() {
game.physics.gravity.y = 50;
@@ -156,15 +241,15 @@ function update() {
// game.physics.collide(group, group);
if (sprite3)
{
game.physics.collideArray(sprite, [sprite2, sprite3]);
game.physics.collide(sprite2, sprite3);
}
else
{
game.physics.collide(sprite, sprite2);
}
// if (sprite3)
// {
// game.physics.collideArray(sprite, [sprite2, sprite3]);
// game.physics.collide(sprite2, sprite3);
// }
// else
// {
// game.physics.collide(sprite, sprite2);
// }
if (sprite)
@@ -192,7 +277,8 @@ function render() {
if (sprite)
{
game.debug.renderBodyInfo(sprite, 16, 24);
game.debug.renderText(sprite.name + ' x: ' + sprite.x, 16, 500);
game.debug.renderText(sprite.name + ' x: ' + sprite.x.toFixed(2) + ' dx: ' + sprite.body._dx.toFixed(2), 16, 500);
game.debug.renderText(sprite.name + ' y: ' + sprite.y.toFixed(2) + ' dy: ' + sprite.body._dy.toFixed(2), 16, 520);
}
if (sprite2)
+2 -4
View File
@@ -26,7 +26,7 @@ function create() {
sprites = game.add.group();
for (var i = 0; i < 100; i++)
for (var i = 0; i < 40; i++)
{
var s = sprites.create(game.rnd.integerInRange(100, 700), game.rnd.integerInRange(32, 200), 'ball');
s.body.velocity.x = game.rnd.integerInRange(-400, 400);
@@ -39,8 +39,6 @@ function create() {
sprites.setAll('body.bounce.y', 0.9);
sprites.setAll('body.minBounceVelocity', 0.8);
console.log(sprites._container.children);
gameboy = game.add.sprite(300, 50, 'gameboy', 0);
gameboy.name = 'gameboy';
gameboy.body.collideWorldBounds = true;
@@ -52,7 +50,7 @@ function create() {
function update() {
// game.physics.collide(gameboy, sprites);
game.physics.collide(gameboy, sprites);
game.physics.collide(sprites);
// sprite.rotation = sprite.body.angle;
+50 -16
View File
@@ -340,24 +340,58 @@ Phaser.Math = {
},
/**
* Set an angle within the bounds of -&pi; to &pi;.
* @method Phaser.Math#normalizeAngle
* @param {number} angle
* @param {boolean} radians - True if angle size is expressed in radians.
* @return {number}
* Reverses an angle.
* @method Phaser.Math#reverseAngle
* @param {number} angleRad - The angle to reverse, in radians.
* @return {number} Returns the reverse angle, in radians.
*/
normalizeAngle: function (angle, radians) {
reverseAngle: function (angleRad) {
return this.normalizeAngle(angleRad + Math.PI, true);
},
if (typeof radians === "undefined") { radians = true; }
/**
* Normalizes an angle to the [0,2pi) range.
* @method Phaser.Math#normalizeAngle
* @param {number} angleRad - The angle to normalize, in radians.
* @return {number} Returns the angle, fit within the [0,2pi] range, in radians.
*/
normalizeAngle: function (angleRad) {
var rd = (radians) ? Math.PI : 180;
return this.wrap(angle, -rd, rd);
angleRad = angleRad % (2 * Math.PI);
return angleRad >= 0 ? angleRad : angleRad + 2 * Math.PI;
},
/**
* Closest angle between two angles from a1 to a2
* absolute value the return for exact angle
* Normalizes a latitude to the [-90,90] range. Latitudes above 90 or below -90 are capped, not wrapped.
* @method Phaser.Math#normalizeLatitude
* @param {number} lat - The latitude to normalize, in degrees.
* @return {number} Returns the latitude, fit within the [-90,90] range.
*/
normalizeLatitude: function (lat) {
return Math.max(-90, Math.min(90, lat));
},
/**
* Normalizes a longitude to the [-180,180] range. Longitudes above 180 or below -180 are wrapped.
* @method Phaser.Math#normalizeLongitude
* @param {number} lng - The longitude to normalize, in degrees.
* @return {number} Returns the longitude, fit within the [-180,180] range.
*/
normalizeLongitude: function (lng) {
if (lng % 360 == 180)
{
return 180;
}
lng = lng % 360;
return lng < -180 ? lng + 360 : lng > 180 ? lng - 360 : lng;
},
/**
* Closest angle between two angles from a1 to a2 absolute value the return for exact angle
* @method Phaser.Math#nearestAngleBetween
* @param {number} a1
* @param {number} a2
@@ -511,13 +545,13 @@ Phaser.Math = {
/**
* Ensures that the value always stays between min and max, by wrapping the value around.
* <p>max should be larger than min, or the function will return 0</p>
* max should be larger than min, or the function will return 0.
*
* @method Phaser.Math#wrap
* @param value The value to wrap
* @param min The minimum the value is allowed to be
* @param max The maximum the value is allowed to be
* @return {number} The wrapped value
* @param {number} value - The value to wrap.
* @param {number} min - The minimum the value is allowed to be.
* @param {number} max - The maximum the value is allowed to be.
* @return {number} The wrapped value.
*/
wrap: function (value, min, max) {
+454 -48
View File
@@ -125,10 +125,16 @@ Phaser.Physics.Arcade.Body = function (sprite) {
this.acceleration = new Phaser.Point();
/**
* @property {number} speed - The speed in pixels per second sq. of the Body.
* @property {number} speed - The speed the Body is traveling.
*/
this.speed = 0;
/**
* @property {number} minDelta - When a body bounces (off a wall or another body) if the resulting delta is less than minDelta, the velocity is cancelled.
* @default
*/
this.minDelta = 0.09;
/**
* @property {number} angle - The angle of the Body in radians.
*/
@@ -137,7 +143,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
/**
* @property {number} minBounceVelocity - The minimum bounce velocity (could just be the bounce value?).
*/
this.minBounceVelocity = 0.5;
// this.minBounceVelocity = 0.2;
this._debug = 0;
@@ -155,7 +161,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
* @property {Phaser.Point} minVelocity - When a body rebounds off another the minVelocity is checked, if the new velocity is lower than the minVelocity the body is stopped.
* @default
*/
this.minVelocity = new Phaser.Point(10, 10);
this.minVelocity = new Phaser.Point(2, 2);
/**
* @property {Phaser.Point} maxVelocity - The maximum velocity that the Body can reach.
@@ -278,10 +284,10 @@ Phaser.Physics.Arcade.Body = function (sprite) {
this.overlapY = 0;
/**
* @property {number} friction - The amount of friction this body experiences during motion.
* @property {number} friction - The amount of friction this body experiences during motion. Friction reduces velocity until the body comes to a stand-still.
* @default
*/
this.friction = 0;
this.friction = 0.1;
/**
* If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true.
@@ -365,13 +371,6 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
preUpdate: function () {
// Store and reset collision flags
// this.wasTouching.none = this.touching.none;
// this.wasTouching.up = this.touching.up;
// this.wasTouching.down = this.touching.down;
// this.wasTouching.left = this.touching.left;
// this.wasTouching.right = this.touching.right;
this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
@@ -379,6 +378,10 @@ Phaser.Physics.Arcade.Body.prototype = {
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = this.preX;
this.y = this.preY;
this.rotation = this.preRotation;
this.blocked.up = false;
this.blocked.down = false;
this.blocked.left = false;
@@ -386,37 +389,24 @@ Phaser.Physics.Arcade.Body.prototype = {
// this.embedded = false;
this.x = this.preX;
this.y = this.preY;
this.rotation = this.preRotation;
this.speed = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y);
this.angle = Math.atan2(this.velocity.y, this.velocity.x);
this._debug++;
if (this.moves)
{
if (this.collideWorldBounds)
{
this.checkWorldBounds();
this.checkWorldBounds(true);
}
this.speed = Math.sqrt(this.velocity.x * this.velocity.x + this.velocity.y * this.velocity.y);
this.angle = Math.atan2(this.velocity.y, this.velocity.x);
this.game.physics.updateMotion(this);
this.applyMotion();
}
if (this.deltaX() != 0)
{
this.touching.left = false;
this.touching.right = false;
}
this.applyFriction();
this.limitVelocity();
if (this.deltaY() != 0)
{
this.touching.up = false;
this.touching.down = false;
}
},
@@ -427,7 +417,7 @@ Phaser.Physics.Arcade.Body.prototype = {
* @method Phaser.Physics.Arcade#checkWorldBounds
* @protected
*/
checkWorldBounds: function () {
ORIGINALcheckWorldBounds: function () {
this.blockedPoint.setTo(0, 0);
@@ -464,12 +454,64 @@ Phaser.Physics.Arcade.Body.prototype = {
},
/**
* Internal method.
* Internal method used to check the Body against the World Bounds and move it back into the bounds again.
*
* @method Phaser.Physics.Arcade#applyMotion
* @method Phaser.Physics.Arcade#checkWorldBounds
* @protected
*/
applyMotion: function () {
checkWorldBounds: function (rebound) {
if (this.x <= this.game.world.bounds.x)
{
this.x += (this.game.world.bounds.x - this.x);
this.blocked.left = true;
// console.log(this._debug, 'cwl', this.overlapX, this.x, this.game.world.bounds.x);
}
else if (this.right >= this.game.world.bounds.right)
{
this.x -= this.right - this.game.world.bounds.right;
this.blocked.right = true;
// console.log(this._debug, 'cwr', this.overlapX, this.x, this.game.world.bounds.x);
}
if (this.y <= this.game.world.bounds.y)
{
this.y += this.game.world.bounds.y - this.y;
this.blocked.up = true;
// console.log(this._debug, 'cwu', this.overlapY, this.y, this.height, this.bottom, this.game.world.bounds.bottom);
}
else if (this.bottom >= this.game.world.bounds.bottom)
{
this.y -= this.bottom - this.game.world.bounds.bottom;
this.blocked.down = true;
// console.log(this._debug, 'cwd', this.overlapY, this.y, this.height, this.bottom, this.game.world.bounds.bottom);
}
// Rebound?
if (rebound && this.speed > 0)
{
var angle = this.game.math.reverseAngle(this.angle);
if ((this.blocked.left || this.blocked.right) && this.bounce.x > 0)
{
this.velocity.x = (Math.cos(angle) * this.speed) * this.bounce.x;
}
if ((this.blocked.up || this.blocked.down) && this.bounce.y > 0)
{
this.velocity.y = (Math.sin(angle) * this.speed) * this.bounce.y;
}
}
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#applyFriction
* @protected
*/
applyFriction: function () {
if (this.friction > 0 && this.acceleration.isZero())
{
@@ -486,15 +528,14 @@ Phaser.Physics.Arcade.Body.prototype = {
this.velocity.y = Math.sin(this.angle) * this.speed;
}
},
/*
worldBounce: function () {
// overlapX/Y values at this point will be penetration into the bounds and DELTA WILL BE ZERO
if (this.blocked.left && this.blockedPoint.x > 0)
if (this.blocked.left)
{
// Separate
// this.x += this.overlapX;
this.x += this.blockedPoint.x;
// console.log(this._debug, 'blocked left', this.x, this.overlapX);
this.velocity.x *= -this.bounce.x;
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
@@ -515,7 +556,7 @@ Phaser.Physics.Arcade.Body.prototype = {
// console.log(this._debug, 'blocked left KILL', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
}
else if (this.blocked.right && this.blockedPoint.x > 0)
else if (this.blocked.right)
{
// Separate
this.x -= this.blockedPoint.x;
@@ -547,7 +588,7 @@ Phaser.Physics.Arcade.Body.prototype = {
}
// overlapX/Y values at this point will be penetration into the bounds and DELTA WILL BE ZERO
if (this.blocked.up && this.blockedPoint.y > 0)
if (this.blocked.up)
{
// Separate
// this.y += this.overlapY;
@@ -572,7 +613,255 @@ Phaser.Physics.Arcade.Body.prototype = {
// console.log(this._debug, 'void1', this.velocity.y, 'delta', this.deltaY());
}
}
else if (this.blocked.down && this.blockedPoint.y > 0)
else if (this.blocked.down)
{
// Separate
// this.y -= this.overlapY;
this.y -= this.blockedPoint.y;
this.velocity.y *= -this.bounce.y;
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
if (this._dy < -this.minBounceVelocity)
// if (Math.abs(this.velocity.y) > this.minVelocity.y)
{
this.y += this._dy;
this.velocity.y += this.motionVelocity.y;
// console.log(this._debug, 'rb', this._dy, 'delta', this.deltaY(), 'newy', this.y);
}
else
{
// Kill it dead :)
this.preY = this.y; // because we don't want any delta from a separation
this.velocity.y = 0;
this.motionVelocity.y = 0;
// console.log(this._debug, 'void1', this.velocity.y, 'delta', this.deltaY());
}
}
else
{
this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
this.velocity.y += this.motionVelocity.y;
}
},
*/
limitVelocity: function (dx, dy) {
if (this.velocity.x > this.maxVelocity.x)
{
this.velocity.x = this.maxVelocity.x;
}
else if (this.velocity.x < -this.maxVelocity.x)
{
this.velocity.x = -this.maxVelocity.x;
}
if (this.velocity.y > this.maxVelocity.y)
{
this.velocity.y = this.maxVelocity.y;
}
else if (this.velocity.y < -this.maxVelocity.y)
{
this.velocity.y = -this.maxVelocity.y;
}
var gx = this.gravity.x + this.game.physics.gravity.x;
var gy = this.gravity.y + this.game.physics.gravity.y;
var stopX = false;
var stopY = false;
if (dx)
{
if (gx > 0 && this.blocked.down && Math.abs(dx) < this.minDelta)
{
// Left pulling gravity
console.log('gx killed 1', dx, gx);
stopX = true;
}
else if (gx < 0 && this.blocked.up && Math.abs(dx) < this.minDelta)
{
// Right pulling gravity
console.log('gx killed 2', dx, gx);
stopX = true;
}
else if (gx === 0 && this.velocity.x !== 0 && Math.abs(this.velocity.x) < this.minVelocity.x)
{
console.log('gx killed 3', this.velocity.x);
stopX = true;
}
if (stopX)
{
this.preX = this.x;
this.velocity.x = 0;
}
}
if (dy)
{
if (gy > 0 && this.blocked.down && Math.abs(dy) < this.minDelta)
{
// Downward gravity
console.log('gy killed 1', dy, gy);
stopY = true;
}
else if (gy < 0 && this.blocked.up && Math.abs(dy) < this.minDelta)
{
// Upward gravity
console.log('gy killed 2', dy, gy);
stopY = true;
}
else if (gy === 0 && this.velocity.y !== 0 && Math.abs(this.velocity.y) < this.minVelocity.y)
{
console.log('gy killed 3', this.velocity.y);
stopY = true;
}
if (stopY)
{
this.preY = this.y;
this.velocity.y = 0;
}
}
if (!stopX && !stopY)
{
return 0;
}
else if (stopX && !stopY)
{
return 1;
}
else if (!stopX && stopY)
{
return 2;
}
else
{
return 3;
}
},
/**
* Internal method.
*
* @method Phaser.Physics.Arcade#applyMotion
* @protected
*/
ORIGINALapplyMotion: function () {
if (this.friction > 0 && this.acceleration.isZero())
{
if (this.speed > this.friction)
{
this.speed -= this.friction;
}
else
{
this.speed = 0;
}
this.velocity.x = Math.cos(this.angle) * this.speed;
this.velocity.y = Math.sin(this.angle) * this.speed;
}
if (this.blocked.isZero())
{
return;
}
// overlapX/Y values at this point will be penetration into the bounds and DELTA WILL BE ZERO
if (this.blocked.left)
{
// Separate
// this.x += this.overlapX;
this.x += this.blockedPoint.x;
// console.log(this._debug, 'blocked left', this.x, this.overlapX);
this.velocity.x *= -this.bounce.x;
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
if (this._dx > this.minBounceVelocity)
// if (Math.abs(this.velocity.x) > this.minVelocity.x)
{
this.x += this._dx;
this.velocity.x += this.motionVelocity.x;
// console.log(this._debug, 'blocked left', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
else
{
// Kill it dead :)
this.preX = this.x; // because we don't want any delta from a separation
this.velocity.x = 0;
this.motionVelocity.x = 0;
// console.log(this._debug, 'blocked left KILL', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
}
else if (this.blocked.right)
{
// Separate
this.x -= this.blockedPoint.x;
// this.x -= this.overlapX;
this.velocity.x *= -this.bounce.x;
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
if (this._dx < -this.minBounceVelocity)
{
this.x += this._dx;
this.velocity.x += this.motionVelocity.x;
// console.log(this._debug, 'blocked right', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
else
{
// Kill it dead :)
this.preX = this.x; // because we don't want any delta from a separation
this.velocity.x = 0;
this.motionVelocity.x = 0;
// console.log(this._debug, 'blocked right KILL', this._dx, 'overlap', this.overlapX, 'delta', this.deltaX(), 'newy', this.x);
}
}
else
{
this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
this.velocity.x += this.motionVelocity.x;
}
// overlapX/Y values at this point will be penetration into the bounds and DELTA WILL BE ZERO
if (this.blocked.up)
{
// Separate
// this.y += this.overlapY;
this.y += this.blockedPoint.y;
this.velocity.y *= -this.bounce.y;
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
if (this._dy > this.minBounceVelocity)
// if (Math.abs(this.velocity.y) > this.minVelocity.y)
{
this.y += this._dy;
this.velocity.y += this.motionVelocity.y;
}
else
{
// Kill it dead :)
this.preY = this.y; // because we don't want any delta from a separation
this.velocity.y = 0;
this.motionVelocity.y = 0;
// console.log(this._debug, 'void1', this.velocity.y, 'delta', this.deltaY());
}
}
else if (this.blocked.down)
{
// Separate
// this.y -= this.overlapY;
@@ -668,13 +957,18 @@ Phaser.Physics.Arcade.Body.prototype = {
this.touching.left = false;
this.touching.right = false;
}
else
else if (Math.abs(this.overlapX) < Math.abs(this.overlapY))
{
// Horizontal penetration (as y is larger than x)
this.overlapY = 0;
this.touching.up = false;
this.touching.down = false;
}
else
{
// They are identical, so let's revert to checking the delta?
console.log('They are identical, so let\'s revert to checking the delta?');
}
}
// overlapX/Y now contains either zero or a positive value containing the overlapping area
@@ -682,6 +976,57 @@ Phaser.Physics.Arcade.Body.prototype = {
},
// Ensure Body is within world limits
worldLimit: function () {
if (!this.collideWorldBounds)
{
return;
}
this.checkWorldBounds();
if (this.blocked.left && this.blockedPoint.x > 0)
{
this.x += this.blockedPoint.x;
this.preX += this.blockedPoint.x;
}
else if (this.blocked.right && this.blockedPoint.x > 0)
{
this.x -= this.blockedPoint.x;
this.preX -= this.blockedPoint.x;
}
if (this.blocked.up && this.blockedPoint.y > 0)
{
this.y += this.blockedPoint.y;
this.preY += this.blockedPoint.y;
}
else if (this.blocked.down && this.blockedPoint.y > 0)
{
this.y -= this.blockedPoint.y;
this.preY -= this.blockedPoint.y;
}
},
separateX: function (x, body, nv1, nv2, avg) {
if (this.immovable || (x < 0 && this.blocked.right) || (x > 0 && this.blocked.left))
{
body.x -= x;
body.velocity.x = this.velocity.x - body.velocity.x * body.bounce.x;
body.worldLimit();
}
// else if (x > 0)
// {
// // right
// }
},
// The left-hand face of this Body was hit
// overlapX will be a positive value
hitLeft: function (x, body, nv1, nv2, avg) {
@@ -691,6 +1036,7 @@ Phaser.Physics.Arcade.Body.prototype = {
{
// console.log(this.sprite.name, 'hitLeft', 'immovable');
body.x -= x;
if (!body.immovable)
body.velocity.x = this.velocity.x - body.velocity.x * body.bounce.x;
}
else
@@ -858,6 +1204,27 @@ Phaser.Physics.Arcade.Body.prototype = {
}
}
if (this.velocity.x > this.maxVelocity.x)
{
this.velocity.x = this.maxVelocity.x;
}
else if (this.velocity.x < -this.maxVelocity.x)
{
this.velocity.x = -this.maxVelocity.x;
}
if (this.velocity.y > this.maxVelocity.y)
{
this.velocity.y = this.maxVelocity.y;
}
else if (this.velocity.y < -this.maxVelocity.y)
{
this.velocity.y = -this.maxVelocity.y;
}
// this.worldLimit();
// body.worldLimit();
},
/**
@@ -870,6 +1237,43 @@ Phaser.Physics.Arcade.Body.prototype = {
if (this.moves)
{
this._dx = this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
this._dy = this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
var result = this.limitVelocity(this._dx, this._dy);
if (result === 0)
{
// Nothing was stopped
this.x += this._dx;
this.velocity.x += this.motionVelocity.x;
this.y += this._dy;
this.velocity.y += this.motionVelocity.y;
}
else if (result === 1)
{
// X was stopped
this.y += this._dy;
this.velocity.y += this.motionVelocity.y;
}
else if (result === 2)
{
// Y was stopped
this.x += this._dx;
this.velocity.x += this.motionVelocity.x;
}
else
{
// Both stopped
}
if (this.collideWorldBounds)
{
this.checkWorldBounds(false);
}
/*
if (this.deltaX() < 0)
{
this.facing = Phaser.LEFT;
@@ -887,6 +1291,9 @@ Phaser.Physics.Arcade.Body.prototype = {
{
this.facing = Phaser.DOWN;
}
*/
console.log(this._debug, this._dx, this.motionVelocity.x);
this.sprite.x += this.deltaX();
this.sprite.y += this.deltaY();
@@ -904,7 +1311,6 @@ Phaser.Physics.Arcade.Body.prototype = {
},
/**
* You can modify the size of the physics Body to be any dimension you need.
* So it could be smaller or larger than the parent Sprite. You can also control the x and y offset, which