Pass TILE_BIAS from arcade world into tile colliding functions

This commit is contained in:
Michael Hadley 2018-01-11 08:32:07 -06:00
parent 718859b02e
commit 5241798ab3
5 changed files with 20 additions and 18 deletions

View file

@ -48,6 +48,8 @@ var World = new Class({
this.OVERLAP_BIAS = GetValue(config, 'overlapBias', 4); this.OVERLAP_BIAS = GetValue(config, 'overlapBias', 4);
this.TILE_BIAS = GetValue(config, 'tileBias', 16);
this.forceX = GetValue(config, 'forceX', false); this.forceX = GetValue(config, 'forceX', false);
this.isPaused = GetValue(config, 'isPaused', false); this.isPaused = GetValue(config, 'isPaused', false);

View file

@ -4,14 +4,16 @@ var ProcessTileCallbacks = require('./tilemap/ProcessTileCallbacks');
var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly)
{ {
if (!sprite.body.enable) var body = sprite.body;
if (!body.enable)
{ {
return false; return false;
} }
var mapData = tilemapLayer.getTilesWithinWorldXY( var mapData = tilemapLayer.getTilesWithinWorldXY(
sprite.body.position.x, sprite.body.position.y, body.position.x, body.position.y,
sprite.body.width, sprite.body.height body.width, body.height
); );
if (mapData.length === 0) if (mapData.length === 0)
@ -30,10 +32,10 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
tileWorldRect.right = tileWorldRect.left + tile.width * tilemapLayer.scaleX; tileWorldRect.right = tileWorldRect.left + tile.width * tilemapLayer.scaleX;
tileWorldRect.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY; tileWorldRect.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY;
if (TileIntersectsBody(tileWorldRect, sprite.body) if (TileIntersectsBody(tileWorldRect, body)
&& (!processCallback || processCallback.call(callbackContext, sprite, tile)) && (!processCallback || processCallback.call(callbackContext, sprite, tile))
&& ProcessTileCallbacks(tile) && ProcessTileCallbacks(tile)
&& (overlapOnly || SeparateTile(i, sprite.body, tile, tileWorldRect, tilemapLayer))) && (overlapOnly || SeparateTile(i, body, tile, tileWorldRect, tilemapLayer, this.TILE_BIAS)))
{ {
this._total++; this._total++;

View file

@ -10,7 +10,7 @@ var TileIntersectsBody = require('./TileIntersectsBody');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {boolean} Returns true if the body was separated, otherwise false. * @return {boolean} Returns true if the body was separated, otherwise false.
*/ */
var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer) var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBias)
{ {
var tileLeft = tileWorldRect.left; var tileLeft = tileWorldRect.left;
var tileTop = tileWorldRect.top; var tileTop = tileWorldRect.top;
@ -55,7 +55,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer)
{ {
if (faceHorizontal) if (faceHorizontal)
{ {
ox = TileCheckX(body, tile, tilemapLayer); ox = TileCheckX(body, tile, tilemapLayer, tileBias);
// That's horizontal done, check if we still intersects? If not then we can return now // That's horizontal done, check if we still intersects? If not then we can return now
if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body)) if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body))
@ -66,14 +66,14 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer)
if (faceVertical) if (faceVertical)
{ {
oy = TileCheckY(body, tile, tilemapLayer); oy = TileCheckY(body, tile, tilemapLayer, tileBias);
} }
} }
else else
{ {
if (faceVertical) if (faceVertical)
{ {
oy = TileCheckY(body, tile, tilemapLayer); oy = TileCheckY(body, tile, tilemapLayer, tileBias);
// That's vertical done, check if we still intersects? If not then we can return now // That's vertical done, check if we still intersects? If not then we can return now
if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body)) if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body))
@ -84,7 +84,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer)
if (faceHorizontal) if (faceHorizontal)
{ {
ox = TileCheckX(body, tile, tilemapLayer); ox = TileCheckX(body, tile, tilemapLayer, tileBias);
} }
} }

View file

@ -1,4 +1,3 @@
var TILE_BIAS = 16;
var ProcessTileSeparationX = require('./ProcessTileSeparationX'); var ProcessTileSeparationX = require('./ProcessTileSeparationX');
/** /**
@ -11,7 +10,7 @@ var ProcessTileSeparationX = require('./ProcessTileSeparationX');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {number} The amount of separation that occurred. * @return {number} The amount of separation that occurred.
*/ */
var TileCheckX = function (body, tile, tilemapLayer) var TileCheckX = function (body, tile, tilemapLayer, tileBias)
{ {
var ox = 0; var ox = 0;
var tileLeft = tilemapLayer.tileToWorldX(tile.x); var tileLeft = tilemapLayer.tileToWorldX(tile.x);
@ -25,7 +24,7 @@ var TileCheckX = function (body, tile, tilemapLayer)
{ {
ox = body.x - tileRight; ox = body.x - tileRight;
if (ox < -TILE_BIAS) if (ox < -tileBias)
{ {
ox = 0; ox = 0;
} }
@ -38,7 +37,7 @@ var TileCheckX = function (body, tile, tilemapLayer)
{ {
ox = body.right - tileLeft; ox = body.right - tileLeft;
if (ox > TILE_BIAS) if (ox > tileBias)
{ {
ox = 0; ox = 0;
} }

View file

@ -1,4 +1,3 @@
var TILE_BIAS = 16;
var ProcessTileSeparationY = require('./ProcessTileSeparationY'); var ProcessTileSeparationY = require('./ProcessTileSeparationY');
/** /**
@ -11,7 +10,7 @@ var ProcessTileSeparationY = require('./ProcessTileSeparationY');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against. * @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {number} The amount of separation that occurred. * @return {number} The amount of separation that occurred.
*/ */
var TileCheckY = function (body, tile, tilemapLayer) var TileCheckY = function (body, tile, tilemapLayer, tileBias)
{ {
var oy = 0; var oy = 0;
var tileTop = tilemapLayer.tileToWorldX(tile.y); var tileTop = tilemapLayer.tileToWorldX(tile.y);
@ -25,7 +24,7 @@ var TileCheckY = function (body, tile, tilemapLayer)
{ {
oy = body.y - tileBottom; oy = body.y - tileBottom;
if (oy < -TILE_BIAS) if (oy < -tileBias)
{ {
oy = 0; oy = 0;
} }
@ -38,7 +37,7 @@ var TileCheckY = function (body, tile, tilemapLayer)
{ {
oy = body.bottom - tileTop; oy = body.bottom - tileTop;
if (oy > TILE_BIAS) if (oy > tileBias)
{ {
oy = 0; oy = 0;
} }