public static int XToTileX(int x,int tileGridXOffset,int tileWidth){
  x-=tileGridXOffset;
  if (x < 0) {
    x+=1 - tileWidth;
  }
  return x / tileWidth;
}

public static int XToTileX ( int x , int tileGridXOffset , int tileWidth ) { x -= tileGridXOffset ; if ( x < 0 ) { x += 1 - tileWidth ; } return x / tileWidth ; }
converts a pixel ' s x coordinate into a horizontal tile index relative to a given tile grid layout specified by its x offset and tile width .
