Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement