List of usage examples for com.badlogic.gdx.graphics.glutils FileTextureData getFileHandle
public FileHandle getFileHandle()
From source file:util.Utils.java
public static Texture peerGem(TiledMapTileLayer layer, String[] ids, TextureAtlas atlas, int cx, int cy) throws Exception { FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData()); InputStream is = ClassLoader.class .getResourceAsStream("/assets/graphics/" + d.getFileHandle().file().getName()); BufferedImage sheet = ImageIO.read(is); BufferedImage canvas = new BufferedImage(32 * layer.getWidth(), 32 * layer.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < layer.getHeight(); y++) { for (int x = 0; x < layer.getWidth(); x++) { String val = ids[layer.getCell(x, layer.getHeight() - y - 1).getTile().getId()]; DungeonTile tile = DungeonTile.getTileByName(val); if (tile == null) { val = "brick_floor"; }/*from w w w . j a v a2 s . c o m*/ if (x == cx && y == cy) { val = "avatar"; } TextureAtlas.AtlasRegion ar = (TextureAtlas.AtlasRegion) atlas.findRegion(val); BufferedImage sub = sheet.getSubimage(ar.getRegionX(), ar.getRegionY(), 32, 32); canvas.getGraphics().drawImage(sub, x * 32, y * 32, 32, 32, null); } } java.awt.Image tmp = canvas.getScaledInstance(20 * 32, 20 * 32, Image.SCALE_AREA_AVERAGING); BufferedImage scaledCanvas = new BufferedImage(20 * 32, 20 * 32, BufferedImage.TYPE_INT_ARGB); scaledCanvas.getGraphics().drawImage(tmp, 0, 0, null); Pixmap p = Utils.createPixmap(scaledCanvas.getWidth(), scaledCanvas.getHeight(), scaledCanvas, 0, 0); Texture t = new Texture(p); p.dispose(); return t; }
From source file:util.Utils.java
public static Texture peerGem(Maps map, TextureAtlas atlas) throws Exception { Texture t = null;//from ww w . j av a2s .com if (map.getMap().getType() == MapType.city) { FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData()); InputStream is = ClassLoader.class .getResourceAsStream("/assets/graphics/" + d.getFileHandle().file().getName()); BufferedImage sheet = ImageIO.read(is); BufferedImage canvas = new BufferedImage(64 * 32, 64 * 32, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < 64; y++) { for (int x = 0; x < 64; x++) { Tile ct = map.getMap().getTile(x, y); TextureAtlas.AtlasRegion ar = (TextureAtlas.AtlasRegion) atlas.findRegion(ct.getName()); BufferedImage sub = sheet.getSubimage(ar.getRegionX(), ar.getRegionY(), 32, 32); canvas.getGraphics().drawImage(sub, x * 32, y * 32, 32, 32, null); Person cr = map.getMap().getPersonAt(x, y); if (cr != null) { canvas.getGraphics().fillRect(x * 32, y * 32, 32, 32); } Drawable obj = map.getMap().getObjectAt(x, y); if (obj != null) { canvas.getGraphics().fillRect(x * 32, y * 32, 32, 32); } } } java.awt.Image tmp = canvas.getScaledInstance(20 * 32, 20 * 32, Image.SCALE_AREA_AVERAGING); BufferedImage scaledCanvas = new BufferedImage(20 * 32, 20 * 32, BufferedImage.TYPE_INT_ARGB); scaledCanvas.getGraphics().drawImage(tmp, 0, 0, null); Pixmap p = createPixmap(Exodus.SCREEN_WIDTH, Exodus.SCREEN_HEIGHT, scaledCanvas, (Exodus.SCREEN_WIDTH - scaledCanvas.getWidth()) / 2, (Exodus.SCREEN_HEIGHT - scaledCanvas.getHeight()) / 2); t = new Texture(p); p.dispose(); } else if (map.getMap().getType() == MapType.dungeon) { //NO OP not needed since I added the minimap already on the HUD } return t; }
From source file:util.Utils.java
public static Texture peerGem(BaseMap worldMap, int avatarX, int avatarY, TextureAtlas atlas) throws Exception { FileTextureData d = (FileTextureData) (atlas.getRegions().first().getTexture().getTextureData()); InputStream is = ClassLoader.class .getResourceAsStream("/assets/graphics/" + d.getFileHandle().file().getName()); BufferedImage sheet = ImageIO.read(is); BufferedImage canvas = new BufferedImage(32 * 64, 32 * 64, BufferedImage.TYPE_INT_ARGB); int startX = avatarX - 32; int startY = avatarY - 32; int endX = avatarX + 32; int endY = avatarY + 32; int indexX = 0; int indexY = 0; for (int y = startY; y < endY; y++) { for (int x = startX; x < endX; x++) { int cx = x; if (x < 0) { cx = 256 + x;//from w w w . j av a2s. c o m } else if (x >= 256) { cx = x - 256; } int cy = y; if (y < 0) { cy = 256 + y; } else if (y >= 256) { cy = y - 256; } Tile ct = worldMap.getTile(cx, cy); TextureAtlas.AtlasRegion ar = (TextureAtlas.AtlasRegion) atlas.findRegion(ct.getName()); BufferedImage sub = sheet.getSubimage(ar.getRegionX(), ar.getRegionY(), 32, 32); canvas.getGraphics().drawImage(sub, indexX * 32, indexY * 32, 32, 32, null); Creature cr = worldMap.getCreatureAt(cx, cy); if (cr != null) { canvas.getGraphics().fillRect(indexX * 32, indexY * 32, 32, 32); } Drawable obj = worldMap.getObjectAt(cx, cy); if (obj != null) { canvas.getGraphics().fillRect(indexX * 32, indexY * 32, 32, 32); } indexX++; } indexX = 0; indexY++; } //add avatar in the middle canvas.getGraphics().fillRect((32 * 64) / 2, (32 * 64) / 2, 32, 32); java.awt.Image tmp = canvas.getScaledInstance(20 * 32, 20 * 32, Image.SCALE_AREA_AVERAGING); BufferedImage scaledCanvas = new BufferedImage(20 * 32, 20 * 32, BufferedImage.TYPE_INT_ARGB); scaledCanvas.getGraphics().drawImage(tmp, 0, 0, null); Pixmap p = createPixmap(Exodus.SCREEN_WIDTH, Exodus.SCREEN_HEIGHT, scaledCanvas, (Exodus.SCREEN_WIDTH - scaledCanvas.getWidth()) / 2, (Exodus.SCREEN_HEIGHT - scaledCanvas.getHeight()) / 2); Texture t = new Texture(p); p.dispose(); return t; }