Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /*
  2. * For Phaser.Plugin.IsoArcard, this helps displayObject placement by moving it above others. This is
  3. * done by moving them up until they no longer overlap with anything.
  4. * @method Phaser.Physics.IsoArcade#placeAboveOverlaps
  5. * @param {any} displayObject - The display object to move.
  6. * @param {any} groupCollision - The the group of displayObjects to check for overlaps with.
  7. * @param {number} [startZ=displayObject.isoZ] - The speed it will move, in pixels per second (default is 60 pixels/sec)
  8. */
  9. function placeAboveOverlaps(displayObject,groupCollision,startZ){
  10. var overlap
  11. startZ = startZ?startZ:displayObject.isoZ;
  12. var deltaZ = displayObject.body.height+game.physics.isoArcade.OVERLAP_BIAS;
  13. var maxZ = game.physics.isoArcade.bounds.height;
  14. var isoBounds = displayObject.isoBounds.copyTo(new Phaser.Plugin.Isometric.Cube());
  15.  
  16. /* Check if two sprites overlap */
  17. function spritesIntersect(displayObject,sprites){
  18. var overlap
  19. for (var i=0; i<sprites.length; i++){
  20. if (sprites[i].isoBounds && sprites[i]!==displayObject && displayObject.id!==sprites[i].id){
  21. overlap = displayObject.isoBounds.intersects(sprites[i].isoBounds)
  22. if (overlap){
  23. return true
  24. }
  25. }
  26. }
  27. return false
  28. }
  29.  
  30. for (var i=startZ; i<maxZ-deltaZ; i+=deltaZ){
  31. // move up and check again
  32. isoBounds.z=i;
  33. overlap = spritesIntersect({isoBounds:isoBounds},groupCollision.children);
  34. if (!overlap){
  35. displayObject.isoZ=i;
  36. displayObject.body.prev.z=i;
  37. return i;
  38. }
  39.  
  40. }
  41. return i;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement