public static Point screenToTile ( MisoSceneMetrics metrics , int sx , int sy , Point tpos ) { // determine the upper-left of the quadrant that contains our point int zx = ( int ) Math . floor ( ( float ) sx / metrics . tilewid ) ; int zy = ( int ) Math . floor ( ( float ) sy / metrics . tilehei ) ; // these are the screen coordinates of the tile's top int ox = ( zx * metrics . tilewid ) , oy = ( zy * metrics . tilehei ) ; // these are the tile coordinates tpos . x = zy + zx ; tpos . y = zy - zx ; // now determine which of the four tiles our point occupies int dx = sx - ox , dy = sy - oy ; if ( Math . round ( metrics . slopeY * dx + metrics . tilehei ) <= dy ) { tpos . x += 1 ; } if ( Math . round ( metrics . slopeX * dx ) > dy ) { tpos . y -= 1 ; } // Log.info("Converted [sx=" + sx + ", sy=" + sy + // ", zx=" + zx + ", zy=" + zy + // ", ox=" + ox + ", oy=" + oy + // ", dx=" + dx + ", dy=" + dy + // ", tpos.x=" + tpos.x + ", tpos.y=" + tpos.y + "]."); return tpos ; }
Convert the given screen - based pixel coordinates to their corresponding tile - based coordinates . Converted coordinates are placed in the given point object .