@@ -36,7 +36,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
3636 point . x = WorldToTileX ( worldX , snapToFloor , camera , layer , orientation ) ;
3737 point . y = WorldToTileY ( worldY , snapToFloor , camera , layer , orientation ) ;
3838 }
39- else if ( orientation === 'isometric' )
39+ else if ( orientation === 'isometric' || orientation === 'staggered' )
4040 {
4141
4242 var tileWidth = layer . baseTileWidth ;
@@ -61,18 +61,39 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
6161
6262 tileWidth *= tilemapLayer . scaleX ;
6363 }
64+
65+ if ( orientation === 'isometric' )
66+ {
67+ point . x = snapToFloor
68+ ? Math . floor ( ( worldX / ( tileWidth / 2 ) + worldY / ( tileHeight / 2 ) ) / 2 )
69+ : ( ( worldX / ( tileWidth / 2 ) + worldY / ( tileHeight / 2 ) ) / 2 ) ;
6470
65- point . x = snapToFloor
66- ? Math . floor ( ( worldX / ( tileWidth / 2 ) + worldY / ( tileHeight / 2 ) ) / 2 )
67- : ( ( worldX / ( tileWidth / 2 ) + worldY / ( tileHeight / 2 ) ) / 2 ) ;
68-
69- point . y = snapToFloor
70- ? Math . floor ( ( worldY / ( tileHeight / 2 ) - worldX / ( tileWidth / 2 ) ) / 2 )
71- : ( ( worldY / ( tileHeight / 2 ) - worldX / ( tileWidth / 2 ) ) / 2 ) ;
71+ point . y = snapToFloor
72+ ? Math . floor ( ( worldY / ( tileHeight / 2 ) - worldX / ( tileWidth / 2 ) ) / 2 )
73+ : ( ( worldY / ( tileHeight / 2 ) - worldX / ( tileWidth / 2 ) ) / 2 ) ;
74+ }
75+ if ( orientation === 'orthogonal' )
76+ {
77+ point . x = snapToFloor
78+ ? Math . floor ( worldX / tileWidth )
79+ : worldX / tileWidth ;
80+ point . y = snapToFloor
81+ ? Math . floor ( worldY / tileHeight )
82+ : worldY / tileHeight ;
83+ }
84+ else if ( orientation === 'staggered' )
85+ {
86+ // implement world to tile staggered
87+ point . y = snapToFloor
88+ ? Math . floor ( ( worldY / ( tileHeight / 2 ) ) )
89+ : ( worldY / ( tileHeight / 2 ) ) ;
90+ point . x = snapToFloor
91+ ? Math . floor ( ( worldX / tileWidth ) - ( point . y % 2 ) )
92+ : ( worldX / tileWidth ) - ( point . y % 2 ) ;
93+
94+ }
7295 }
7396
74-
75-
7697 return point ;
7798} ;
7899
0 commit comments