"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