Skip to content

Instantly share code, notes, and snippets.

@JakeSteam
Last active February 12, 2019 02:34
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JakeSteam/cb6cd823a74f2c32723396ef9a8c91ec to your computer and use it in GitHub Desktop.
"Android: Displaying Levels At Optimum Zoom" helper functions for GameDevAlgorithms
public int getTileWidth() {
return dpToPixel(Constants.TILE_WIDTH);
}
public int getTileHeight() {
return dpToPixel(Constants.TILE_HEIGHT);
}
public int dpToPixel(float dp) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return (int) px;
}
public static Pair<Integer, Integer> getMaxXY(List<Tile> tiles) {
int maxX = 0;
int maxY = 0;
for (Tile tile : tiles) {
if (tile.getX() > maxX) {
maxX = tile.getX();
}
if (tile.getY() > maxY) {
maxY = tile.getY();
}
}
return new Pair<>(maxX, maxY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment