Guest User

Untitled

a guest
May 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. - orientation = `orthogonal`
  2.  
  3. - TileToWorldX
  4.  
  5. ```javascript
  6. var TileToWorldX = function(tileX, tileY) {
  7. return tileX * tile.width;
  8. }
  9. ```
  10. - TileToWorldY
  11.  
  12. ```javascript
  13. var TileToWorldY = function(tileX, tileY) {
  14. return tileY * tile.height;
  15. }
  16. ```
  17. - WorldToTileX
  18. ```javascript
  19. var WorldToTileX = function(worldX, worldY) {
  20. return Math.floor( worldX / tile.width );
  21. }
  22. ```
  23. - WorldToTileY
  24. ```javascript
  25. var WorldToTileY = function(worldX, worldY) {
  26. return Math.floor( worldY / tile.height );
  27. }
  28. ```
  29.  
  30. - orientation = `isometric`
  31. - TileToWorldX
  32.  
  33. ```javascript
  34. var TileToWorldX = function(tileX, tileY) {
  35. return (tileX - tileY) * (tile.width * 0.5);
  36. }
  37. ```
  38. - TileToWorldY
  39.  
  40. ```javascript
  41. var TileToWorldY = function(tileX, tileY) {
  42. return (tileX + tileY) * (tile.height * 0.5);
  43. }
  44. ```
  45. - WorldToTileX
  46. ```javascript
  47. var WorldToTileX = function(worldX, worldY) {
  48. return 0.5 * (
  49. Math.floor(worldY / (tile.height * 0.5)) +
  50. Math.floor(worldX / (tile.width * 0.5))
  51. );
  52. }
  53. ```
  54. - WorldToTileY
  55. ```javascript
  56. var WorldToTileY = function(worldX, worldY) {
  57. return 0.5 * (
  58. Math.floor(worldY / (tile.height * 0.5)) -
  59. Math.floor(worldX / (tile.width * 0.5))
  60. );
  61. }
  62. ```
Add Comment
Please, Sign In to add comment