for (String name : page.addedRects) { PixmapPackerRectangle rect = page.rects.get(name); TextureAtlas.AtlasRegion region = new TextureAtlas.AtlasRegion(page.texture, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
powerup.position.x - Constants.POWERUP_CENTER.x, powerup.position.y - Constants.POWERUP_CENTER.y, Assets.instance.powerupAssets.powerup.getRegionWidth(), Assets.instance.powerupAssets.powerup.getRegionHeight() ); if (gigaGalBounds.overlaps(powerupBounds)) {
float iconPosY = getStage().getViewport().getScreenHeight() - charIcon.getRegionHeight() * scale - DPIUtils.getMarginSize(); posy = Math.min(posy, iconPosY);
batch.draw(charIcon, getX() - charIcon.getRegionWidth() * scale, getY(), charIcon.getRegionWidth() * scale, charIcon.getRegionHeight() * scale);
@Override public void render() { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); // Don't do this! This results in drawing the entire texture atlas, not just the region you're interested in // batch.draw(standingRight.getTexture(), 0, 0); // TODO: Draw the standing right AtlasRegion // Hint, you need to use the somewhat horrific version of draw with signature: // draw (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, // float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) batch.draw( standingRight.getTexture(), 0, 0, 0, 0, standingRight.getRegionWidth(), standingRight.getRegionHeight(), 1, 1, 0, standingRight.getRegionX(), standingRight.getRegionY(), standingRight.getRegionWidth(), standingRight.getRegionHeight(), false, false); batch.end(); }
int width = region.width; int height = region.height; AtlasRegion atlasRegion = new AtlasRegion(pageToTexture.get(region.page), region.left, region.top, region.rotate ? height : width, region.rotate ? width : height); atlasRegion.index = region.index; atlasRegion.splits = region.splits; atlasRegion.pads = region.pads; if (region.flip) atlasRegion.flip(false, true); regions.add(atlasRegion);
(int) (r.getRegionHeight() * 200f / r.getRegionWidth()));
width += background.get(i).getRegionWidth(); int height = background.get(0).getRegionHeight();
TextureAtlas.AtlasRegion atlasRegion = textureAtlas.findRegion(getLocalizedString(imageModel.getFrame())); if (imageModel.isFlipX() || imageModel.isFlipY()) { atlasRegion = new TextureAtlas.AtlasRegion(atlasRegion); atlasRegion.flip(imageModel.isFlipX(), imageModel.isFlipY());
/** Updates the {@link TextureAtlas}, adding any new {@link Pixmap} instances packed since the last call to this method. This * can be used to insert Pixmap instances on a separate thread via {@link #pack(String, Pixmap)} and update the TextureAtlas on * the rendering thread. This method must be called on the rendering thread. After calling this method, disposing the packer * will no longer dispose the page pixmaps. */ public synchronized void updateTextureAtlas (TextureAtlas atlas, TextureFilter minFilter, TextureFilter magFilter, boolean useMipMaps) { updatePageTextures(minFilter, magFilter, useMipMaps); for (Page page : pages) { if (page.addedRects.size > 0) { for (String name : page.addedRects) { PixmapPackerRectangle rect = page.rects.get(name); TextureAtlas.AtlasRegion region = new TextureAtlas.AtlasRegion(page.texture, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); if (rect.splits != null) { region.splits = rect.splits; region.pads = rect.pads; } region.name = name; region.index = -1; region.offsetX = rect.offsetX; region.offsetY = (int)(rect.originalHeight - rect.height - rect.offsetY); region.originalWidth = rect.originalWidth; region.originalHeight = rect.originalHeight; atlas.getRegions().add(region); } page.addedRects.clear(); atlas.getTextures().add(page.texture); } } }
@Override public void flip (boolean x, boolean y) { // Flip texture. if (region.rotate) super.flip(y, x); else super.flip(x, y); float oldOriginX = getOriginX(); float oldOriginY = getOriginY(); float oldOffsetX = region.offsetX; float oldOffsetY = region.offsetY; float widthRatio = getWidthRatio(); float heightRatio = getHeightRatio(); region.offsetX = originalOffsetX; region.offsetY = originalOffsetY; region.flip(x, y); // Updates x and y offsets. originalOffsetX = region.offsetX; originalOffsetY = region.offsetY; region.offsetX *= widthRatio; region.offsetY *= heightRatio; // Update position and origin with new offsets. translate(region.offsetX - oldOffsetX, region.offsetY - oldOffsetY); setOrigin(oldOriginX, oldOriginY); }
public void draw(SpriteBatch batch) { if (background != null) { batch.disableBlending(); batch.setProjectionMatrix(camera.calculateParallaxMatrix(1, 1)); batch.begin(); float x = 0; for (AtlasRegion tile : background) { batch.draw(tile, x, 0f); x += tile.getRegionWidth(); } batch.end(); batch.enableBlending(); } // draw layers from bottom to top for (int i = layers.size() - 1; i >= 0; i--) { SceneLayer layer = layers.get(i); batch.setProjectionMatrix(camera.calculateParallaxMatrix(layer.getParallaxMultiplier(), 1)); batch.begin(); layer.draw(batch); batch.end(); } }
public float getWidthRatio () { return super.getWidth() / region.getRotatedPackedWidth(); }
public AtlasSprite (AtlasRegion region) { this.region = new AtlasRegion(region); originalOffsetX = region.offsetX; originalOffsetY = region.offsetY; setRegion(region); setOrigin(region.originalWidth / 2f, region.originalHeight / 2f); int width = region.getRegionWidth(); int height = region.getRegionHeight(); if (region.rotate) { super.rotate90(true); super.setBounds(region.offsetX, region.offsetY, height, width); } else super.setBounds(region.offsetX, region.offsetY, width, height); setColor(1, 1, 1, 1); }
public float getHeightRatio () { return super.getHeight() / region.getRotatedPackedHeight(); }
public AtlasRegion (AtlasRegion region) { setRegion(region); index = region.index; name = region.name; offsetX = region.offsetX; offsetY = region.offsetY; packedWidth = region.packedWidth; packedHeight = region.packedHeight; originalWidth = region.originalWidth; originalHeight = region.originalHeight; rotate = region.rotate; splits = region.splits; }
@Override public float getWidth () { return super.getWidth() / region.getRotatedPackedWidth() * region.originalWidth; }
@Override public float getHeight () { return super.getHeight() / region.getRotatedPackedHeight() * region.originalHeight; }