Java Code Examples for com.badlogic.gdx.graphics.g2d.TextureRegion#getTexture()

The following examples show how to use com.badlogic.gdx.graphics.g2d.TextureRegion#getTexture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From skin-composer with MIT License 6 votes vote down vote up
public static Pixmap textureRegionToPixmap(TextureRegion textureRegion) {
    var texture = textureRegion.getTexture();
    if (!texture.getTextureData().isPrepared()) {
        texture.getTextureData().prepare();
    }
    
    var pixmap = texture.getTextureData().consumePixmap();
    var returnValue = new Pixmap(textureRegion.getRegionWidth(), textureRegion.getRegionHeight(), Pixmap.Format.RGBA8888);
    returnValue.setBlending(Pixmap.Blending.None);
    
    for (int x = 0; x < textureRegion.getRegionWidth(); x++) {
        for (int y = 0; y < textureRegion.getRegionHeight(); y++) {
            int colorInt = pixmap.getPixel(textureRegion.getRegionX() + x, textureRegion.getRegionY() + y);
            returnValue.drawPixel(x, y, colorInt);
        }
    }
    
    pixmap.dispose();
    
    return returnValue;
}
 
Example 2
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Splits the image 
 * @param image
 * @param width
 * @param height
 * @param row
 * @param col
 * @return
 */
public static TextureRegion[] splitImage(TextureRegion image, int width, int height, int row, int col) {                
    int total = col * row; // total returned images
    int frame = 0; // frame counter

    int w = width / col;
    int h = height / row;

    TextureRegion[] images = new TextureRegion[total];

    for (int j = 0; j < row; j++) {
        for (int i = 0; i < col; i++) {                
            TextureRegion region = new TextureRegion(image.getTexture(), i * w, j * h, w, h);
            //region.flip(false, true);
            images[frame++] = region;
        }
    }

    return images;
}
 
Example 3
Source File: RadialDrawable.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public void setTextureRegion(final TextureRegion textureRegion) {
    this.texture = textureRegion.getTexture();
    this.u1 = textureRegion.getU();
    this.v1 = textureRegion.getV();
    this.u2 = textureRegion.getU2();
    this.v2 = textureRegion.getV2();
    this.du = u2 - u1;
    this.dv = v2 - v1;
    this.width = textureRegion.getRegionWidth();
    this.height = textureRegion.getRegionHeight();
    this.dirty = true;

    setMinWidth(textureRegion.getRegionWidth());
    setMinHeight(textureRegion.getRegionHeight());
}
 
Example 4
Source File: LibgdxTextureRegionWrapper.java    From mini2Dx with Apache License 2.0 4 votes vote down vote up
/** Constructs a region with the same texture and coordinates of the specified region. */
public LibgdxTextureRegionWrapper (TextureRegion region) {
	if (region.getTexture() != null){
		super.setRegion(region);
	}
}
 
Example 5
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets a subImage.
 *
 * @param image
 * @param x
 * @param y
 * @param width
 * @param height
 * @return
 */
public static TextureRegion subImage(TextureRegion image, int x, int y, int width, int height) {
    return new TextureRegion(image.getTexture(), x, y, width, height);
}