mirror of
https://github.com/wassname/phaser.git
synced 2026-07-04 17:20:31 +08:00
Physics integration and a fix to Tween that stopped the repeat/yoyo from working.
This commit is contained in:
@@ -27,20 +27,20 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
body.sprite.rotation += body.angularVelocity * this.game.time.elapsed;
|
||||
body.sprite.rotation += body.angularVelocity * this.game.time.physicsElapsed;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
|
||||
body.velocity.x += this._velocityDelta;
|
||||
this._delta = body.velocity.x * this.game.time.elapsed;
|
||||
this._delta = body.velocity.x * this.game.time.physicsElapsed;
|
||||
body.velocity.x += this._velocityDelta;
|
||||
body.sprite.x += this._delta;
|
||||
body._x += this._delta;
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
|
||||
body.velocity.y += this._velocityDelta;
|
||||
this._delta = body.velocity.y * this.game.time.elapsed;
|
||||
this._delta = body.velocity.y * this.game.time.physicsElapsed;
|
||||
body.velocity.y += this._velocityDelta;
|
||||
body.sprite.y += this._delta;
|
||||
body._y += this._delta;
|
||||
|
||||
},
|
||||
|
||||
@@ -63,11 +63,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
if (acceleration !== 0)
|
||||
{
|
||||
velocity += (acceleration + gravity) * this.game.time.elapsed;
|
||||
velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
|
||||
}
|
||||
else if (drag !== 0)
|
||||
{
|
||||
this._drag = drag * this.game.time.elapsed;
|
||||
this._drag = drag * this.game.time.physicsElapsed;
|
||||
|
||||
if (velocity - this._drag > 0)
|
||||
{
|
||||
|
||||
+138
-9
@@ -2,12 +2,36 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
|
||||
this.sprite = sprite;
|
||||
this.game = sprite.game;
|
||||
this.bounds = new Phaser.Rectangle(sprite.x, sprite.y, sprite.currentFrame.sourceSizeW, sprite.currentFrame.sourceSizeH);
|
||||
|
||||
this.hitArea = new Phaser.Rectangle(sprite.x, sprite.y, sprite.currentFrame.sourceSizeW, sprite.currentFrame.sourceSizeH);
|
||||
this.offset = new Phaser.Point;
|
||||
|
||||
this._w = sprite.width;
|
||||
this._h = sprite.height;
|
||||
this.width = this.hitArea.width;
|
||||
this.height = this.hitArea.height;
|
||||
this._sx = sprite.scale.x;
|
||||
this._sy = sprite.scale.y;
|
||||
|
||||
this.velocity = new Phaser.Point;
|
||||
this.acceleration = new Phaser.Point;
|
||||
this.drag = new Phaser.Point;
|
||||
this.gravity = new Phaser.Point;
|
||||
this.bounce = new Phaser.Point;
|
||||
this.maxVelocity = new Phaser.Point(10000, 10000);
|
||||
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.angularDrag = 0;
|
||||
this.maxAngular = 1000;
|
||||
this.mass = 1;
|
||||
|
||||
this.touching = 0;
|
||||
this.wasTouching = 0;
|
||||
this.allowCollisions = 1;
|
||||
|
||||
this._x = sprite.x;
|
||||
this._y = sprite.y;
|
||||
this._ox = sprite.x;
|
||||
this._oy = sprite.y;
|
||||
|
||||
};
|
||||
|
||||
@@ -15,15 +39,120 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
sprite: null,
|
||||
game: null,
|
||||
bounds: null,
|
||||
hitArea: null,
|
||||
|
||||
update: function () {
|
||||
update: function (x, y, scaleX, scaleY) {
|
||||
|
||||
this.bounds.x = this.sprite.x - (this.sprite.anchor.x * (this.offset.x * this.sprite.scale.x));
|
||||
this.bounds.y = this.sprite.y - (this.sprite.anchor.y * (this.offset.y * this.sprite.scale.y));
|
||||
this.bounds.width = this._w * this.sprite.scale.x;
|
||||
this.bounds.height = this._h * this.sprite.scale.y;
|
||||
if (scaleX != this._sx || scaleY != this._sy)
|
||||
{
|
||||
this.hitArea.width = this.width * scaleX;
|
||||
this.hitArea.height = this.height * scaleY;
|
||||
this._sx = scaleX;
|
||||
this._sy = scaleY;
|
||||
}
|
||||
|
||||
this.hitArea.centerX = x;
|
||||
this.hitArea.centerY = y;
|
||||
|
||||
// this._ox = x;
|
||||
// this._oy = y;
|
||||
|
||||
},
|
||||
|
||||
updateMotion: function () {
|
||||
|
||||
this._ox = this._x;
|
||||
this._oy = this._y;
|
||||
|
||||
this.game.physics.updateMotion(this);
|
||||
|
||||
// delta force - _x and _y now contain the new positions, so work out the deltas
|
||||
// separation and stuff happens here
|
||||
|
||||
},
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
sprite.x = this._x;
|
||||
sprite.y = this._y;
|
||||
|
||||
},
|
||||
|
||||
setSize: function (width, height) {
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.hitArea.width = this.width * scaleX;
|
||||
this.hitArea.height = this.height * scaleY;
|
||||
|
||||
},
|
||||
|
||||
hullWidth: function () {
|
||||
|
||||
if (this.deltaX > 0)
|
||||
{
|
||||
return this.hitArea.width + this.deltaX;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.hitArea.width - this.deltaX;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hullHeight: function () {
|
||||
|
||||
if (this.deltaY > 0)
|
||||
{
|
||||
return this.hitArea.height + this.deltaY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.hitArea.height - this.deltaY;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hullX: function () {
|
||||
|
||||
if (this._x < this._ox)
|
||||
{
|
||||
return this._x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this._ox;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hullY: function () {
|
||||
|
||||
if (this._y < this._oy)
|
||||
{
|
||||
return this._y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this._oy;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
deltaXAbs: function () {
|
||||
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
|
||||
},
|
||||
|
||||
deltaYAbs: function () {
|
||||
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
|
||||
},
|
||||
|
||||
deltaX: function () {
|
||||
return this._x - this._ox;
|
||||
},
|
||||
|
||||
deltaY: function () {
|
||||
return this._y - this._oy;
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user