Created
February 18, 2013 21:18
-
-
Save coreh/4980837 to your computer and use it in GitHub Desktop.
How to calculate sprite coordinates by index in a sprite-sheet with fixed-sized sprites.
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
// These are known beforehand | |
int imageWidth = 640; | |
int imageHeight = 480; | |
int tileWidth = 32; | |
int tileHeight = 32; | |
int tilesPerRow = imageWidth / tileWidth; | |
int index = 5; | |
int left = tileWidth * (index % tilesPerRow); | |
int top = tileHeight * (index / tilesPerRow); | |
int bottom = top + tileHeight; | |
int right = top + tileWidth; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment