mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
Pass TILE_BIAS from arcade world into tile colliding functions
This commit is contained in:
parent
718859b02e
commit
5241798ab3
5 changed files with 20 additions and 18 deletions
|
@ -48,6 +48,8 @@ var World = new Class({
|
|||
|
||||
this.OVERLAP_BIAS = GetValue(config, 'overlapBias', 4);
|
||||
|
||||
this.TILE_BIAS = GetValue(config, 'tileBias', 16);
|
||||
|
||||
this.forceX = GetValue(config, 'forceX', false);
|
||||
|
||||
this.isPaused = GetValue(config, 'isPaused', false);
|
||||
|
|
|
@ -4,14 +4,16 @@ var ProcessTileCallbacks = require('./tilemap/ProcessTileCallbacks');
|
|||
|
||||
var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly)
|
||||
{
|
||||
if (!sprite.body.enable)
|
||||
var body = sprite.body;
|
||||
|
||||
if (!body.enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var mapData = tilemapLayer.getTilesWithinWorldXY(
|
||||
sprite.body.position.x, sprite.body.position.y,
|
||||
sprite.body.width, sprite.body.height
|
||||
body.position.x, body.position.y,
|
||||
body.width, body.height
|
||||
);
|
||||
|
||||
if (mapData.length === 0)
|
||||
|
@ -30,10 +32,10 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
|
|||
tileWorldRect.right = tileWorldRect.left + tile.width * tilemapLayer.scaleX;
|
||||
tileWorldRect.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY;
|
||||
|
||||
if (TileIntersectsBody(tileWorldRect, sprite.body)
|
||||
if (TileIntersectsBody(tileWorldRect, body)
|
||||
&& (!processCallback || processCallback.call(callbackContext, sprite, tile))
|
||||
&& ProcessTileCallbacks(tile)
|
||||
&& (overlapOnly || SeparateTile(i, sprite.body, tile, tileWorldRect, tilemapLayer)))
|
||||
&& (overlapOnly || SeparateTile(i, body, tile, tileWorldRect, tilemapLayer, this.TILE_BIAS)))
|
||||
{
|
||||
this._total++;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ var TileIntersectsBody = require('./TileIntersectsBody');
|
|||
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
|
||||
* @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 tileTop = tileWorldRect.top;
|
||||
|
@ -55,7 +55,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer)
|
|||
{
|
||||
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
|
||||
if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body))
|
||||
|
@ -66,14 +66,14 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer)
|
|||
|
||||
if (faceVertical)
|
||||
{
|
||||
oy = TileCheckY(body, tile, tilemapLayer);
|
||||
oy = TileCheckY(body, tile, tilemapLayer, tileBias);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body))
|
||||
|
@ -84,7 +84,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer)
|
|||
|
||||
if (faceHorizontal)
|
||||
{
|
||||
ox = TileCheckX(body, tile, tilemapLayer);
|
||||
ox = TileCheckX(body, tile, tilemapLayer, tileBias);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var TILE_BIAS = 16;
|
||||
var ProcessTileSeparationX = require('./ProcessTileSeparationX');
|
||||
|
||||
/**
|
||||
|
@ -11,7 +10,7 @@ var ProcessTileSeparationX = require('./ProcessTileSeparationX');
|
|||
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
|
||||
* @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 tileLeft = tilemapLayer.tileToWorldX(tile.x);
|
||||
|
@ -25,7 +24,7 @@ var TileCheckX = function (body, tile, tilemapLayer)
|
|||
{
|
||||
ox = body.x - tileRight;
|
||||
|
||||
if (ox < -TILE_BIAS)
|
||||
if (ox < -tileBias)
|
||||
{
|
||||
ox = 0;
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ var TileCheckX = function (body, tile, tilemapLayer)
|
|||
{
|
||||
ox = body.right - tileLeft;
|
||||
|
||||
if (ox > TILE_BIAS)
|
||||
if (ox > tileBias)
|
||||
{
|
||||
ox = 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var TILE_BIAS = 16;
|
||||
var ProcessTileSeparationY = require('./ProcessTileSeparationY');
|
||||
|
||||
/**
|
||||
|
@ -11,7 +10,7 @@ var ProcessTileSeparationY = require('./ProcessTileSeparationY');
|
|||
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
|
||||
* @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 tileTop = tilemapLayer.tileToWorldX(tile.y);
|
||||
|
@ -25,7 +24,7 @@ var TileCheckY = function (body, tile, tilemapLayer)
|
|||
{
|
||||
oy = body.y - tileBottom;
|
||||
|
||||
if (oy < -TILE_BIAS)
|
||||
if (oy < -tileBias)
|
||||
{
|
||||
oy = 0;
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ var TileCheckY = function (body, tile, tilemapLayer)
|
|||
{
|
||||
oy = body.bottom - tileTop;
|
||||
|
||||
if (oy > TILE_BIAS)
|
||||
if (oy > tileBias)
|
||||
{
|
||||
oy = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue