Skip to content

Commit 306fbf4

Browse files
committed
Merge pull request phaserjs#1810 from Preece/tilemap-overlap
Sprite vs Tilemap can now check for overlap, without trying to separate
2 parents 88524cd + e935df3 commit 306fbf4

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/physics/arcade/TilemapCollision.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
3434
* @param {object} callbackContext - The context in which to run the callbacks.
3535
* @param {boolean} overlapOnly - Just run an overlap or a full collision.
3636
*/
37-
collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext) {
37+
collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) {
3838

3939
if (!sprite.body)
4040
{
@@ -59,7 +59,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
5959
{
6060
if (processCallback.call(callbackContext, sprite, mapData[i]))
6161
{
62-
if (this.separateTile(i, sprite.body, mapData[i]))
62+
if (this.separateTile(i, sprite.body, mapData[i], overlapOnly))
6363
{
6464
this._total++;
6565

@@ -72,7 +72,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
7272
}
7373
else
7474
{
75-
if (this.separateTile(i, sprite.body, mapData[i]))
75+
if (this.separateTile(i, sprite.body, mapData[i], overlapOnly))
7676
{
7777
this._total++;
7878

@@ -98,7 +98,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
9898
* @param {object} callbackContext - The context in which to run the callbacks.
9999
* @param {boolean} overlapOnly - Just run an overlap or a full collision.
100100
*/
101-
collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) {
101+
collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) {
102102

103103
if (group.length === 0)
104104
{
@@ -109,7 +109,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
109109
{
110110
if (group.children[i].exists)
111111
{
112-
this.collideSpriteVsTilemapLayer(group.children[i], tilemapLayer, collideCallback, processCallback, callbackContext);
112+
this.collideSpriteVsTilemapLayer(group.children[i], tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly);
113113
}
114114
}
115115

@@ -124,14 +124,24 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
124124
* @param {Phaser.Tile} tile - The tile to collide against.
125125
* @return {boolean} Returns true if the body was separated, otherwise false.
126126
*/
127-
separateTile: function (i, body, tile) {
127+
separateTile: function (i, body, tile, overlapOnly) {
128+
129+
if (!body.enable)
130+
{
131+
return false;
132+
}
128133

129134
// We re-check for collision in case body was separated in a previous step
130-
if (!body.enable || !tile.intersects(body.position.x, body.position.y, body.right, body.bottom))
135+
if (!tile.intersects(body.position.x, body.position.y, body.right, body.bottom))
131136
{
132137
// no collision so bail out (separated in a previous step)
133138
return false;
134139
}
140+
else if (overlapOnly)
141+
{
142+
// There is an overlap, and we don't need to separate. Bail.
143+
return true;
144+
}
135145

136146
// They overlap. Any custom callbacks?
137147

src/physics/arcade/World.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ Phaser.Physics.Arcade.prototype = {
617617
}
618618
else if (object2.physicsType === Phaser.TILEMAPLAYER)
619619
{
620-
this.collideSpriteVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext);
620+
this.collideSpriteVsTilemapLayer(object1, object2, collideCallback, processCallback, callbackContext, overlapOnly);
621621
}
622622
}
623623
// GROUPS

0 commit comments

Comments
 (0)