Last active
February 12, 2019 02:34
-
-
Save JakeSteam/cb6cd823a74f2c32723396ef9a8c91ec to your computer and use it in GitHub Desktop.
"Android: Displaying Levels At Optimum Zoom" helper functions for GameDevAlgorithms
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
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; | |
} |
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
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