use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion 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.TextureAtlas.AtlasRegion 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.TextureAtlas.AtlasRegion in project libgdx by libgdx.
the class TextureAtlasTest method create.
public void create() {
batch = new SpriteBatch();
renderer = new ShapeRenderer();
atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
jumpAnimation = new Animation(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));
badlogic = atlas.createSprite("badlogicslice");
badlogic.setPosition(50, 50);
// badlogicSmall = atlas.createSprite("badlogicsmall");
badlogicSmall = atlas.createSprite("badlogicsmall-rotated");
badlogicSmall.setPosition(10, 10);
AtlasRegion region = atlas.findRegion("badlogicsmall");
System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);
System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);
star = atlas.createSprite("particle-star");
star.setPosition(10, 70);
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
Gdx.gl.glClearColor(0, 1, 0, 1);
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean keyUp(int keycode) {
if (keycode == Keys.UP) {
badlogicSmall.flip(false, true);
} else if (keycode == Keys.RIGHT) {
badlogicSmall.flip(true, false);
} else if (keycode == Keys.LEFT) {
badlogicSmall.setSize(512, 512);
} else if (keycode == Keys.DOWN) {
badlogicSmall.rotate90(true);
}
return super.keyUp(keycode);
}
});
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project libgdx by libgdx.
the class TextureRegionDrawable method tint.
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */
public Drawable tint(Color tint) {
Sprite sprite;
if (region instanceof AtlasRegion)
sprite = new AtlasSprite((AtlasRegion) region);
else
sprite = new Sprite(region);
sprite.setColor(tint);
sprite.setSize(getMinWidth(), getMinHeight());
SpriteDrawable drawable = new SpriteDrawable(sprite);
drawable.setLeftWidth(getLeftWidth());
drawable.setRightWidth(getRightWidth());
drawable.setTopHeight(getTopHeight());
drawable.setBottomHeight(getBottomHeight());
return drawable;
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project libgdx by libgdx.
the class Skin method getDrawable.
/** Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the
* appropriate drawable is created and stored in the skin. */
public Drawable getDrawable(String name) {
Drawable drawable = optional(name, Drawable.class);
if (drawable != null)
return drawable;
// Use texture or texture region. If it has splits, use ninepatch. If it has rotation or whitespace stripping, use sprite.
try {
TextureRegion textureRegion = getRegion(name);
if (textureRegion instanceof AtlasRegion) {
AtlasRegion region = (AtlasRegion) textureRegion;
if (region.splits != null)
drawable = new NinePatchDrawable(getPatch(name));
else if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
drawable = new SpriteDrawable(getSprite(name));
}
if (drawable == null)
drawable = new TextureRegionDrawable(textureRegion);
} catch (GdxRuntimeException ignored) {
}
// Check for explicit registration of ninepatch, sprite, or tiled drawable.
if (drawable == null) {
NinePatch patch = optional(name, NinePatch.class);
if (patch != null)
drawable = new NinePatchDrawable(patch);
else {
Sprite sprite = optional(name, Sprite.class);
if (sprite != null)
drawable = new SpriteDrawable(sprite);
else
throw new GdxRuntimeException("No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: " + name);
}
}
if (drawable instanceof BaseDrawable)
((BaseDrawable) drawable).setName(name);
add(name, drawable, Drawable.class);
return drawable;
}
Aggregations