Search in sources :

Example 1 with TextureRegion

use of com.badlogic.gdx.graphics.g2d.TextureRegion in project netthreads-libgdx by alistairrutherford.

the class TextureCache method load.

/**
	 * Load predefined textures.
	 * 
	 * This requires texture definitions to be added to the {@link AppActorTextures} structure.
	 */
public void load(List<TextureDefinition> textureDefinitions) {
    if (textureAtlas == null) {
        textureAtlas = new TextureAtlas();
    } else {
        dispose();
        textureAtlas = new TextureAtlas();
    }
    for (TextureDefinition definition : textureDefinitions) {
        Texture texture = new Texture(Gdx.files.internal(definition.getPath()));
        TextureRegion textureRegion = new TextureRegion(texture);
        textureAtlas.addRegion(definition.getName(), textureRegion);
        definitions.put(definition.getName(), definition);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Texture(com.badlogic.gdx.graphics.Texture)

Example 2 with TextureRegion

use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.

the class TextureAtlasPanel method setAtlas.

public void setAtlas(TextureAtlas atlas) {
    if (atlas == this.atlas)
        return;
    regionsPanel.removeAll();
    Array<AtlasRegion> atlasRegions = atlas.getRegions();
    CustomCardLayout layout = (CustomCardLayout) regionsPanel.getLayout();
    Array<TextureRegion> regions = new Array<TextureRegion>();
    for (Texture texture : atlas.getTextures()) {
        FileTextureData file = (FileTextureData) texture.getTextureData();
        regionsPanel.add(new TexturePanel(texture, getRegions(texture, atlasRegions, regions)));
    }
    layout.first(regionsPanel);
    this.atlas = atlas;
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) FileTextureData(com.badlogic.gdx.graphics.glutils.FileTextureData) Texture(com.badlogic.gdx.graphics.Texture)

Example 3 with TextureRegion

use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.

the class RegionPickerPanel method generateRegions.

void generateRegions(GenerationMode mode) {
    //generate regions
    texturePanel.clear();
    Texture texture = texturePanel.getTexture();
    int rows = (int) rowSlider.getValue(), columns = (int) columnSlider.getValue(), yOffset = texture.getHeight() / rows, xOffset = texture.getWidth() / columns;
    if (mode == GenerationMode.ByRows) {
        for (int j = 0; j < rows; ++j) {
            int rowOffset = j * yOffset;
            for (int i = 0; i < columns; ++i) {
                texturePanel.unselectedRegions.add(new TextureRegion(texture, i * xOffset, rowOffset, xOffset, yOffset));
            }
        }
    } else if (mode == GenerationMode.ByColumns) {
        for (int i = 0; i < columns; ++i) {
            int columnOffset = i * xOffset;
            for (int j = 0; j < rows; ++j) {
                texturePanel.unselectedRegions.add(new TextureRegion(texture, columnOffset, j * yOffset, xOffset, yOffset));
            }
        }
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture)

Example 4 with TextureRegion

use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.

the class BitmapFontLoader method loadSync.

@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) {
    if (parameter != null && parameter.atlasName != null) {
        TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class);
        String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString();
        AtlasRegion region = atlas.findRegion(name);
        if (region == null)
            throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName);
        return new BitmapFont(file, region);
    } else {
        int n = data.getImagePaths().length;
        Array<TextureRegion> regs = new Array(n);
        for (int i = 0; i < n; i++) {
            regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class)));
        }
        return new BitmapFont(data, regs, true);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 5 with TextureRegion

use of com.badlogic.gdx.graphics.g2d.TextureRegion in project libgdx by libgdx.

the class BaseTmxMapLoader method loadImageLayer.

protected void loadImageLayer(TiledMap map, Element element, FileHandle tmxFile, ImageResolver imageResolver) {
    if (element.getName().equals("imagelayer")) {
        int x = Integer.parseInt(element.getAttribute("x", "0"));
        int y = Integer.parseInt(element.getAttribute("y", "0"));
        if (flipY)
            y = mapHeightInPixels - y;
        TextureRegion texture = null;
        Element image = element.getChildByName("image");
        if (image != null) {
            String source = image.getAttribute("source");
            FileHandle handle = getRelativeFileHandle(tmxFile, source);
            texture = imageResolver.getImage(handle.path());
            y -= texture.getRegionHeight();
        }
        TiledMapImageLayer layer = new TiledMapImageLayer(texture, x, y);
        loadBasicLayerInfo(layer, element);
        Element properties = element.getChildByName("properties");
        if (properties != null) {
            loadProperties(layer.getProperties(), properties);
        }
        map.getLayers().add(layer);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) FileHandle(com.badlogic.gdx.files.FileHandle) Element(com.badlogic.gdx.utils.XmlReader.Element)

Aggregations

TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)115 Texture (com.badlogic.gdx.graphics.Texture)57 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)22 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)18 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)13 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)13 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)11 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)11 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)10 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)10 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)10 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Color (com.badlogic.gdx.graphics.Color)7 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)7 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)7 Test (org.junit.Test)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)6