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 commons-gdx by gemserk.
the class SpriteUtilsTest method shouldReturnNotAliasWhenAtlasRegionsAreNotEqual.
@Test
public void shouldReturnNotAliasWhenAtlasRegionsAreNotEqual() {
Sprite sprite1 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 40, 40));
Sprite sprite2 = new AtlasSprite(new AtlasRegion(texture512x512, 50, 30, 20, 40));
assertFalse(SpriteUtils.isAliasSprite(sprite1, sprite2));
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project commons-gdx by gemserk.
the class SpriteUtilsTest method shouldReturnAliasWhenAtlasRegionsAreEqual.
@Test
public void shouldReturnAliasWhenAtlasRegionsAreEqual() {
AtlasRegion atlasRegion1 = new AtlasRegion(texture512x512, 50, 30, 40, 40);
AtlasRegion atlasRegion2 = new AtlasRegion(texture512x512, 50, 30, 40, 40);
Sprite sprite1 = new AtlasSprite(atlasRegion1);
Sprite sprite2 = new AtlasSprite(atlasRegion2);
assertTrue(SpriteUtils.isAliasSprite(sprite1, sprite2));
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion in project commons-gdx by gemserk.
the class FontResourceBuilder method build.
@Override
public BitmapFont build() {
BitmapFont bitmapFont;
if (imageFile != null && fontFile != null) {
Texture texture = new Texture(imageFile);
texture.setFilter(minFilter, magFilter);
bitmapFont = new BitmapFont(fontFile, new Sprite(texture), false);
} else if (textureAtlasId != null && regionId != null) {
if (fontFile == null)
throw new IllegalArgumentException("Can't build a font resource without specifying the fontFile.");
TextureAtlas atlas = resourceManager.getResourceValue(textureAtlasId);
AtlasRegion region = atlas.findRegion(regionId);
if (region == null)
throw new IllegalArgumentException("Can't build a font resource, region " + regionId + " not found in texture atlas");
bitmapFont = new BitmapFont(fontFile, region, false);
} else {
// if image file and font file are not specified, it creates a new default bitmap font.
bitmapFont = new BitmapFont();
bitmapFont.getRegion().getTexture().setFilter(minFilter, magFilter);
}
bitmapFont.setUseIntegerPositions(useIntegerPositions);
if (fixedWidthGlyphs != null)
bitmapFont.setFixedWidthGlyphs(fixedWidthGlyphs);
for (int i = 0; i < spacings.size(); i++) {
FontSpacing fontSpacing = spacings.get(i);
CharSequence charSequence = fontSpacing.charSequence;
BitmapFontUtils.spacing(bitmapFont, charSequence, fontSpacing.spacing);
}
bitmapFont.setScale(scale);
return bitmapFont;
}
Aggregations