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);
}
}
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;
}
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));
}
}
}
}
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);
}
}
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);
}
}
Aggregations