@Override public TextureRegion getImage (String name) { return atlas.findRegion(name); } }
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.setPosition(10, 70); font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
@Override public TextureRegion getImage (String name) { return atlas.findRegion(name); } }
AtlasRegion region = atlas.findRegion(regionName); if (region == null) throw new GdxRuntimeException("Tileset region not found: " + regionName); tile = new StaticTiledMapTile(region);
void setTextureFilter (int filter) { atlas.findRegion("map").getTexture().bind(); Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, filters[filter]); texture.bind(); Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, filters[filter]); }
AtlasRegion region = atlas.findRegion(regionName); if (region == null) throw new GdxRuntimeException("Tileset region not found: " + regionName); tile = new StaticTiledMapTile(region);
public void create () { TextureAtlas textureAtlas = new TextureAtlas("data/pack"); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), textureAtlas.findRegion("verdana39"), false); singleLineCache = new BitmapFontCache(font, true); multiLineCache = new BitmapFontCache(font, true); singleLineCacheNonInteger = new BitmapFontCache(font, false); multiLineCacheNonInteger = new BitmapFontCache(font, false); batch = new SpriteBatch(); fillCaches(); }
@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); } }
@Override public void create () { spriteBatch = new SpriteBatch(); atlas = new TextureAtlas("data/pack"); smallFont = new BitmapFont(); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), atlas.findRegion("verdana39"), false); font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false); renderer = new ShapeRenderer(); renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix()); }
@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); } }
private void compare (TextureAtlas original, TextureAtlas.AtlasRegion loaded) { final TextureAtlas.AtlasRegion originalRegion = original.findRegion(loaded.name); if (originalRegion == null) throw new GdxRuntimeException("No original AtlasRegion found"); if (originalRegion.index != loaded.index) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.offsetX != loaded.offsetX) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.offsetY != loaded.offsetY) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.packedWidth != loaded.packedWidth) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.packedHeight != loaded.packedHeight) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.originalWidth != loaded.originalWidth) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.originalHeight != loaded.originalHeight) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.rotate != loaded.rotate) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); if (originalRegion.splits != null && loaded.splits != null) { for (int i = 0; i < originalRegion.splits.length; i++) { if (originalRegion.splits[i] != loaded.splits[i]) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); } } else { if (originalRegion.splits != loaded.splits) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); } if (originalRegion.pads != null && loaded.pads != null) { for (int i = 0; i < originalRegion.pads.length; i++) { if (originalRegion.pads[i] != loaded.pads[i]) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); } } else { if (originalRegion.pads != loaded.pads) throw new GdxRuntimeException("Original AtlasRegion differs from loaded"); } }
@Override public void render () { // clear the screen, update the camera and make the sprite batch // use its matrices. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); batch.setProjectionMatrix(camera.combined); // render all the things, we render in a y-down // cartesian coordinate system batch.begin(); // drawing a region, x and y will be the top left corner of the region, would be bottom left // with y-up. batch.draw(region, 20, 100); // drawing text, x and y will be the top left corner for text, same as with y-up font.draw(batch, "This is a test", 270, 100); // drawing regions from an atlas, x and y will be the top left corner. // you shouldn't call findRegion every frame, cache the result. batch.draw(atlas.findRegion("badlogicsmall"), 360, 100); // drawing a sprite created from an atlas, FIXME wut?! AtlasSprite#setPosition seems to be wrong sprite.setColor(Color.RED); sprite.draw(batch); // finally we draw our current touch/mouse coordinates font.draw(batch, Gdx.input.getX() + ", " + Gdx.input.getY(), 0, 0); batch.end(); // tell the stage to act and draw itself stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); }
@Override public void render () { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); texture.bind(0); shader.begin(); shader.setUniformMatrix("u_projView", matrix); shader.setUniformi("u_texture", 0); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); batch.begin(); batch.draw(atlas.findRegion("font"), 0, 100); sprite.rotate(Gdx.graphics.getDeltaTime() * 45); for (Vector2 position : positions) { sprite.setPosition(position.x, position.y); sprite.draw(batch); } font.draw(batch, "fps:" + Gdx.graphics.getFramesPerSecond() + ", delta: " + Gdx.graphics.getDeltaTime() + ", #sprites: " + numSprites, 0, 30); cache.setPosition(200, 200); cache.draw(batch); batch.end(); }
if (manager.isLoaded("data/verdana39.png")) batch.draw(manager.get("data/verdana39.png", Texture.class), 300, 100); if (manager.isLoaded("data/pack")) batch.draw(manager.get("data/pack", TextureAtlas.class).findRegion("particle-star"), 164, 100); if (manager.isLoaded("data/verdana39.fnt")) manager.get("data/verdana39.fnt", BitmapFont.class).draw(batch, "This is a test", 100, 80);
@Override public TextureRegion getImage (String name) { return atlas.findRegion(name); } }
TextureAtlas mAtlas; TextureRegionDrawable drawableUp = new TextureRegionDrawable( mAtlas.findRegion("up") ); TextureRegionDrawable drawableDown = new TextureRegionDrawable( mAtlas.findRegion("down") ); TextureRegionDrawable drawableChecked = new TextureRegionDrawable( mAtlas.findRegion("checked") ); ButtonStyle btnStyle = new ButtonStyle(drawableUp, drawableDown, drawableChecked); Button t = new Button(btnStyle);
private void loadIcons (Drawable[] target, String prefix) { target[0] = new TextureRegionDrawable(highResTextures.findRegion(prefix + "-small")); target[1] = new TextureRegionDrawable(highResTextures.findRegion(prefix + "-medium")); target[2] = new TextureRegionDrawable(highResTextures.findRegion(prefix + "-big")); }
public Pointer(Skin skin) { pointerIcon = skin.getAtlas().findRegion(POINTER_ICON); setTouchable(Touchable.disabled); resize(); show(); }
public Turtle(PlayScreen screen, float x, float y) { super(screen, x, y); frames = new Array<TextureRegion>(); frames.add(new TextureRegion(screen.getAtlas().findRegion("turtle"), 0, 0, 16, 24)); frames.add(new TextureRegion(screen.getAtlas().findRegion("turtle"), 16, 0, 16, 24)); shell = new TextureRegion(screen.getAtlas().findRegion("turtle"), 64, 0, 16, 24); walkAnimation = new Animation(0.2f, frames); currentState = previousState = State.WALKING; setBounds(getX(), getY(), 16 / MarioBros.PPM, 24 / MarioBros.PPM); }
public Goomba(PlayScreen screen, float x, float y) { super(screen, x, y); frames = new Array<TextureRegion>(); for(int i = 0; i < 2; i++) frames.add(new TextureRegion(screen.getAtlas().findRegion("goomba"), i * 16, 0, 16, 16)); walkAnimation = new Animation(0.4f, frames); stateTime = 0; setBounds(getX(), getY(), 16 / MarioBros.PPM, 16 / MarioBros.PPM); setToDestroy = false; destroyed = false; angle = 0; }