Created
February 24, 2016 06:44
-
-
Save poemdexter/04c800d8e6fcaffa7b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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