Skip to content

Instantly share code, notes, and snippets.

@poemdexter
Created February 24, 2016 06:44
Show Gist options
  • Save poemdexter/04c800d8e6fcaffa7b72 to your computer and use it in GitHub Desktop.
Save poemdexter/04c800d8e6fcaffa7b72 to your computer and use it in GitHub Desktop.
Vector2 pixelToTile (Vector2 mouseInput) {
//Tiles are what size?
if (tileSize == 0) {
tileSize = tileGrid[0][0].toUse.getWidth();
}
int x = Math.floor(mouseInput.x / tileSize);
int y = Math.floor(mouseInput.y / tileSize);
y = size - 1 - y;
if (mouseInput.x < 0) x = 0;
else if (mouseInput.x >= size) x = size - 1;
if (mouseInput.y < 0) y = 0;
else if (mouseInput.y >= size) y = size - 1;
return new Vector2(x,y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment