mirror of
https://github.com/wassname/phaser.git
synced 2026-10-01 12:21:02 +08:00
Lots of new tilemap code in here. If your game relies on tilemaps then please don't update to this commit unless you want to help debugging!
This commit is contained in:
1 parent
cd314cd03e
commit
ea3802a556
11 files changed
+762
-63
No files matched your search
@@ -610,11 +610,6 @@ Phaser.Physics.Arcade.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (group.length === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (group._container.first._iNext)
|
||||
{
|
||||
var currentNode = group._container.first._iNext;
|
||||
@@ -995,7 +990,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
* @param {Phaser.Tile} tile - The tile to collide against.
|
||||
* @returns {boolean} Returns true if the bodies were separated, otherwise false.
|
||||
*/
|
||||
separateTile: function (body, tile) {
|
||||
XseparateTile: function (body, tile) {
|
||||
|
||||
this._result = (this.separateTileX(body, tile, true) || this.separateTileY(body, tile, true));
|
||||
|
||||
@@ -1003,6 +998,110 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
},
|
||||
|
||||
separateTile: function (body, tile) {
|
||||
|
||||
// Can't separate two immovable objects (tiles are always immovable)
|
||||
if (body.immovable || Phaser.Rectangle.intersects(body, tile) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var overlapX = 0;
|
||||
var overlapY = 0;
|
||||
|
||||
console.log('x', tile.x, 'y', tile.y, 'r', tile.right, 'b', tile.bottom);
|
||||
console.log('x', body.x, 'y', body.y, 'r', body.right, 'b', body.bottom);
|
||||
console.log(Phaser.Rectangle.intersects(body, tile));
|
||||
|
||||
if (body.deltaX() < 0 && body.allowCollision.left && tile.tile.faceRight)
|
||||
{
|
||||
// LEFT
|
||||
if (tile.right - body.x < Math.ceil(body.deltaAbsX()))
|
||||
{
|
||||
overlapX = tile.right - body.x;
|
||||
|
||||
body.touching.left = true;
|
||||
body.touching.none = false;
|
||||
}
|
||||
}
|
||||
else if (body.deltaX() > 0 && body.allowCollision.right && tile.tile.faceLeft)
|
||||
{
|
||||
// RIGHT
|
||||
if (body.right - tile.x < Math.ceil(body.deltaAbsX()))
|
||||
{
|
||||
overlapX = tile.x - body.right;
|
||||
|
||||
body.touching.right = true;
|
||||
body.touching.none = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (body.deltaY() < 0 && body.allowCollision.up && tile.tile.faceBottom)
|
||||
{
|
||||
// UP
|
||||
if (tile.bottom - body.y < Math.ceil(body.deltaAbsY()))
|
||||
{
|
||||
overlapY = tile.bottom - body.y;
|
||||
|
||||
body.touching.up = true;
|
||||
body.touching.none = false;
|
||||
}
|
||||
}
|
||||
else if (body.deltaY() > 0 && body.allowCollision.down && tile.tile.faceTop)
|
||||
{
|
||||
// DOWN
|
||||
if (body.bottom - tile.y < Math.ceil(body.deltaAbsY()))
|
||||
{
|
||||
overlapY = tile.y - body.bottom;
|
||||
|
||||
body.touching.down = true;
|
||||
body.touching.none = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Separate in a single sweep
|
||||
|
||||
if (overlapX === 0 && overlapY === 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (overlapX !== 0)
|
||||
{
|
||||
// body.overlapX = overlapX;
|
||||
body.x += overlapX;
|
||||
body.preX = body.x;
|
||||
|
||||
if (body.bounce.x === 0)
|
||||
{
|
||||
body.velocity.x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body.velocity.x = -body.velocity.x * body.bounce.x;
|
||||
}
|
||||
}
|
||||
|
||||
if (overlapY !== 0)
|
||||
{
|
||||
// body.overlapY = overlapY;
|
||||
body.y += overlapY;
|
||||
body.preY = body.y;
|
||||
|
||||
if (body.bounce.y === 0)
|
||||
{
|
||||
body.velocity.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body.velocity.y = -body.velocity.y * body.bounce.y;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The core separation function to separate a physics body and a tile on the x axis.
|
||||
* @method Phaser.Physics.Arcade#separateTileX
|
||||
@@ -1059,6 +1158,8 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
if (separate)
|
||||
{
|
||||
// console.log('dx1', body.x);
|
||||
|
||||
if (body.deltaX() < 0)
|
||||
{
|
||||
body.x = body.x + this._overlap;
|
||||
@@ -1068,6 +1169,8 @@ Phaser.Physics.Arcade.prototype = {
|
||||
body.x = body.x - this._overlap;
|
||||
}
|
||||
|
||||
// console.log('dx2', body.x, this._overlap);
|
||||
|
||||
if (body.bounce.x === 0)
|
||||
{
|
||||
body.velocity.x = 0;
|
||||
@@ -1077,7 +1180,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
body.velocity.x = -body.velocity.x * body.bounce.x;
|
||||
}
|
||||
|
||||
body.updateHulls();
|
||||
body.updateHulls(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1163,7 +1266,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
body.velocity.y = -body.velocity.y * body.bounce.y;
|
||||
}
|
||||
|
||||
body.updateHulls();
|
||||
body.updateHulls(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -286,6 +286,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
*/
|
||||
this.overlapY = 0;
|
||||
|
||||
this.hull = new Phaser.Rectangle();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} hullX - The dynamically calculated hull used during collision.
|
||||
*/
|
||||
@@ -368,6 +370,9 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.y = this.preY;
|
||||
this.rotation = this.preRotation;
|
||||
|
||||
this.overlapX = 0;
|
||||
this.overlapY = 0;
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.game.physics.updateMotion(this);
|
||||
@@ -377,7 +382,11 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
|
||||
this.updateHulls();
|
||||
this.hull.setTo(this.preX, this.preY, this.width, this.height);
|
||||
|
||||
// this.hullX.setTo(this.x, this.preY, this.width, this.height);
|
||||
// this.hullY.setTo(this.preX, this.y, this.width, this.height);
|
||||
this.updateHulls(true);
|
||||
}
|
||||
|
||||
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
|
||||
@@ -415,8 +424,37 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.facing = Phaser.DOWN;
|
||||
}
|
||||
|
||||
/*
|
||||
if (this.overlapX !== 0)
|
||||
{
|
||||
this.sprite.x += this.overlapX;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.deltaX() !== 0)
|
||||
{
|
||||
this.sprite.x += this.deltaX();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.overlapY !== 0)
|
||||
{
|
||||
this.sprite.y += this.overlapY;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.deltaY() !== 0)
|
||||
{
|
||||
this.sprite.y += this.deltaY();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (this.deltaX() !== 0 || this.deltaY() !== 0)
|
||||
{
|
||||
// console.log('dx', this.deltaX());
|
||||
// console.log('dy', this.deltaY());
|
||||
|
||||
this.sprite.x += this.deltaX();
|
||||
this.sprite.y += this.deltaY();
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
@@ -435,10 +473,21 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @method Phaser.Physics.Arcade#updateHulls
|
||||
* @protected
|
||||
*/
|
||||
updateHulls: function () {
|
||||
updateHulls: function (separation) {
|
||||
|
||||
this.hullX.setTo(this.x, this.preY, this.width, this.height);
|
||||
this.hullY.setTo(this.preX, this.y, this.width, this.height);
|
||||
// this.hull.setTo(this.x, this.y, this.width, this.height);
|
||||
|
||||
// if (separation)
|
||||
// {
|
||||
// this.hullX.setTo(this.x, this.preY, this.width, this.height);
|
||||
// this.hullY.setTo(this.preX, this.y, this.width, this.height);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if this has separated then the preX/Y values are no longer valid
|
||||
// this.hullX.setTo(this.x, this.y, this.width, this.height);
|
||||
// this.hullY.setTo(this.x, this.y, this.width, this.height);
|
||||
// }
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user