For Phaser.Plugin.IsoArcarde, this helps displayObject placement by moving it above others. This is done by moving them up until they no longer overlap with anything.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* For Phaser.Plugin.IsoArcard, this helps displayObject placement by moving it above others. This is | |
* done by moving them up until they no longer overlap with anything. | |
* @method Phaser.Physics.IsoArcade#placeAboveOverlaps | |
* @param {any} displayObject - The display object to move. | |
* @param {any} groupCollision - The the group of displayObjects to check for overlaps with. | |
* @param {number} [startZ=displayObject.isoZ] - The speed it will move, in pixels per second (default is 60 pixels/sec) | |
*/ | |
function placeAboveOverlaps(displayObject,groupCollision,startZ){ | |
var overlap | |
startZ = startZ?startZ:displayObject.isoZ; | |
var deltaZ = displayObject.body.height+game.physics.isoArcade.OVERLAP_BIAS; | |
var maxZ = game.physics.isoArcade.bounds.height; | |
var isoBounds = displayObject.isoBounds.copyTo(new Phaser.Plugin.Isometric.Cube()); | |
/* Check if two sprites overlap */ | |
function spritesIntersect(displayObject,sprites){ | |
var overlap | |
for (var i=0; i<sprites.length; i++){ | |
if (sprites[i].isoBounds && sprites[i]!==displayObject && displayObject.id!==sprites[i].id){ | |
overlap = displayObject.isoBounds.intersects(sprites[i].isoBounds) | |
if (overlap){ | |
return true | |
} | |
} | |
} | |
return false | |
} | |
for (var i=startZ; i<maxZ-deltaZ; i+=deltaZ){ | |
// move up and check again | |
isoBounds.z=i; | |
overlap = spritesIntersect({isoBounds:isoBounds},groupCollision.children); | |
if (!overlap){ | |
displayObject.isoZ=i; | |
displayObject.body.prev.z=i; | |
return i; | |
} | |
} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment