/** Sets the texture to that of the specified region and sets the coordinates relative to the specified region. */ public void setRegion (TextureRegion region, int x, int y, int width, int height) { texture = region.texture; setRegion(region.getRegionX() + x, region.getRegionY() + y, width, height); }
/** Sets the texture to that of the specified region and sets the coordinates relative to the specified region. */ public void setRegion (TextureRegion region, int x, int y, int width, int height) { texture = region.texture; setRegion(region.getRegionX() + x, region.getRegionY() + y, width, height); }
private void draw (Graphics g, Array<TextureRegion> regions, Color color, boolean drawIndex) { int i=0; for(TextureRegion region : regions){ int x = region.getRegionX(), y = region.getRegionY(), h = region.getRegionHeight(); if(drawIndex){ String indexString = ""+i; Rectangle bounds = g.getFontMetrics().getStringBounds(indexString, g).getBounds(); g.setColor(indexBackgroundColor); g.fillRect(x, y+h-bounds.height, bounds.width, bounds.height); g.setColor(indexColor); g.drawString(indexString, x, y+h); ++i; } g.setColor(color); g.drawRect(x, y, region.getRegionWidth(), h); } } }
private void draw (Graphics g, Array<TextureRegion> regions, Color color, boolean drawIndex) { int i=0; for(TextureRegion region : regions){ int x = region.getRegionX(), y = region.getRegionY(), h = region.getRegionHeight(); if(drawIndex){ String indexString = ""+i; Rectangle bounds = g.getFontMetrics().getStringBounds(indexString, g).getBounds(); g.setColor(indexBackgroundColor); g.fillRect(x, y+h-bounds.height, bounds.width, bounds.height); g.setColor(indexColor); g.drawString(indexString, x, y+h); ++i; } g.setColor(color); g.drawRect(x, y, region.getRegionWidth(), h); } } }
/** Helper function to create tiles out of this TextureRegion starting from the top left corner going to the right and ending at * the bottom right corner. Only complete tiles will be returned so if the region's width or height are not a multiple of the * tile width and height not all of the region will be used. This will not work on texture regions returned form a TextureAtlas * that either have whitespace removed or where flipped before the region is split. * * @param tileWidth a tile's width in pixels * @param tileHeight a tile's height in pixels * @return a 2D array of TextureRegions indexed by [row][column]. */ public TextureRegion[][] split (int tileWidth, int tileHeight) { int x = getRegionX(); int y = getRegionY(); int width = regionWidth; int height = regionHeight; int rows = height / tileHeight; int cols = width / tileWidth; int startX = x; TextureRegion[][] tiles = new TextureRegion[rows][cols]; for (int row = 0; row < rows; row++, y += tileHeight) { x = startX; for (int col = 0; col < cols; col++, x += tileWidth) { tiles[row][col] = new TextureRegion(texture, x, y, tileWidth, tileHeight); } } return tiles; }
protected boolean isInsideRegion (TextureRegion region, float x, float y) { float rx = region.getRegionX(), ry = region.getRegionY(); return rx <= x && x <= rx +region.getRegionWidth() && ry <= y && y <= ry +region.getRegionHeight(); }
/** Helper function to create tiles out of this TextureRegion starting from the top left corner going to the right and ending at * the bottom right corner. Only complete tiles will be returned so if the region's width or height are not a multiple of the * tile width and height not all of the region will be used. This will not work on texture regions returned form a TextureAtlas * that either have whitespace removed or where flipped before the region is split. * * @param tileWidth a tile's width in pixels * @param tileHeight a tile's height in pixels * @return a 2D array of TextureRegions indexed by [row][column]. */ public TextureRegion[][] split (int tileWidth, int tileHeight) { int x = getRegionX(); int y = getRegionY(); int width = regionWidth; int height = regionHeight; int rows = height / tileHeight; int cols = width / tileWidth; int startX = x; TextureRegion[][] tiles = new TextureRegion[rows][cols]; for (int row = 0; row < rows; row++, y += tileHeight) { x = startX; for (int col = 0; col < cols; col++, x += tileWidth) { tiles[row][col] = new TextureRegion(texture, x, y, tileWidth, tileHeight); } } return tiles; }
protected boolean isInsideRegion (TextureRegion region, float x, float y) { float rx = region.getRegionX(), ry = region.getRegionY(); return rx <= x && x <= rx +region.getRegionWidth() && ry <= y && y <= ry +region.getRegionHeight(); }
/** Sets the texture to that of the specified region and sets the coordinates relative to the specified region. */ public void setRegion (TextureRegion region, int x, int y, int width, int height) { texture = region.texture; setRegion(region.getRegionX() + x, region.getRegionY() + y, width, height); }
private void draw (Graphics g, Array<TextureRegion> regions, Color color, boolean drawIndex) { int i=0; for(TextureRegion region : regions){ int x = region.getRegionX(), y = region.getRegionY(), h = region.getRegionHeight(); if(drawIndex){ String indexString = ""+i; Rectangle bounds = g.getFontMetrics().getStringBounds(indexString, g).getBounds(); g.setColor(indexBackgroundColor); g.fillRect(x, y+h-bounds.height, bounds.width, bounds.height); g.setColor(indexColor); g.drawString(indexString, x, y+h); ++i; } g.setColor(color); g.drawRect(x, y, region.getRegionWidth(), h); } } }
protected boolean isInsideRegion (TextureRegion region, float x, float y) { float rx = region.getRegionX(), ry = region.getRegionY(); return rx <= x && x <= rx +region.getRegionWidth() && ry <= y && y <= ry +region.getRegionHeight(); }
/** Helper function to create tiles out of this TextureRegion starting from the top left corner going to the right and ending at * the bottom right corner. Only complete tiles will be returned so if the region's width or height are not a multiple of the * tile width and height not all of the region will be used. This will not work on texture regions returned form a TextureAtlas * that either have whitespace removed or where flipped before the region is split. * * @param tileWidth a tile's width in pixels * @param tileHeight a tile's height in pixels * @return a 2D array of TextureRegions indexed by [row][column]. */ public TextureRegion[][] split (int tileWidth, int tileHeight) { int x = getRegionX(); int y = getRegionY(); int width = regionWidth; int height = regionHeight; int rows = height / tileHeight; int cols = width / tileWidth; int startX = x; TextureRegion[][] tiles = new TextureRegion[rows][cols]; for (int row = 0; row < rows; row++, y += tileHeight) { x = startX; for (int col = 0; col < cols; col++, x += tileWidth) { tiles[row][col] = new TextureRegion(texture, x, y, tileWidth, tileHeight); } } return tiles; }
/** Adds a region to the atlas. The texture for the specified region will be disposed when the atlas is disposed. */ public AtlasRegion addRegion (String name, TextureRegion textureRegion) { return addRegion(name, textureRegion.texture, textureRegion.getRegionX(), textureRegion.getRegionY(), textureRegion.getRegionWidth(), textureRegion.getRegionHeight()); }
@Override public int getRegionY() { setFlipY(!isFlipY()); int result = super.getRegionY(); setFlipY(!isFlipY()); return result; }
public class PixmapHelper { static Pixmap fullGraphics ; static Pixmap miniObject; public static void Initialize() { fullGraphics =AssetLoader.GetPixmap(Settings.TEX_MAP_OBJECTS); miniObject=new Pixmap(8,8, Pixmap.Format.RGBA8888); } static void Draw(TextureRegion textureRegion,Texture dstTexture,int dstX,int dstY) { miniObject.drawPixmap(fullGraphics, 0,0, textureRegion.getRegionX(),textureRegion.getRegionY(), textureRegion.getRegionWidth(),textureRegion.getRegionHeight()); dstTexture.draw(miniObject,dstX,dstY); } }
public static void drawTextureRegion(SpriteBatch batch, TextureRegion region, float x, float y) { batch.draw( region.getTexture(), x, y, 0, 0, region.getRegionWidth(), region.getRegionHeight(), 1, 1, 0, region.getRegionX(), region.getRegionY(), region.getRegionWidth(), region.getRegionHeight(), false, false); }
private void drawRegionCentered(SpriteBatch batch, TextureRegion region, float x, float y) { batch.draw( region.getTexture(), x - region.getRegionWidth() / 2, y - region.getRegionHeight() / 2, 0, 0, region.getRegionWidth(), region.getRegionHeight(), 1, 1, 0, region.getRegionX(), region.getRegionY(), region.getRegionWidth(), region.getRegionHeight(), false, false); }
position.x + origin.x, position.y + origin.y, test.getWidth(), test.getHeight(), reg.getRegionX(), reg.getRegionY(), reg.getRegionWidth(), reg.getRegionHeight() );
/** * Calculates the average color of a texture region. * * @param region The texture region * @return The average color */ public static Color getAverageColorFor(TextureRegion region) { region.getTexture().getTextureData().prepare(); final Pixmap pixmap = region.getTexture().getTextureData().consumePixmap(); float total = region.getRegionHeight() * region.getRegionWidth(); float r = 0, g = 0, b = 0; for (int y = region.getRegionY(), yMax = region.getRegionY() + region.getRegionHeight(); y < yMax; y++) { for (int x = region.getRegionX(), xMax = region.getRegionX() + region.getRegionWidth(); x < xMax; x++) { int pixel = pixmap.getPixel(x, y); // Ignore certain alpha colors if (((pixel & 0x000000ff)) / 255f < 0.0625f) { total--; continue; } r += ((pixel & 0xff000000) >>> 24) / 255f; g += ((pixel & 0x00ff0000) >>> 16) / 255f; b += ((pixel & 0x0000ff00) >>> 8) / 255f; } } if (region.getTexture().getTextureData().disposePixmap()) { pixmap.dispose(); } return new Color(r / total, g / total, b / total, 1f); }
angle.rotation, frame.getRegionX(), frame.getRegionY(), frame.getRegionWidth(), frame.getRegionHeight(),