public void setU (float u) { this.u = u; regionWidth = Math.round(Math.abs(u2 - u) * texture.getWidth()); }
/** Creates a sprite with width, height, and texture region equal to the size of the texture. */ public Sprite (Texture texture) { this(texture, 0, 0, texture.getWidth(), texture.getHeight()); }
/** @param width The width of the texture region. May be negative to flip the sprite when drawn. * @param height The height of the texture region. May be negative to flip the sprite when drawn. */ public void setRegion (int x, int y, int width, int height) { float invTexWidth = 1f / texture.getWidth(); float invTexHeight = 1f / texture.getHeight(); setRegion(x * invTexWidth, y * invTexHeight, (x + width) * invTexWidth, (y + height) * invTexHeight); regionWidth = Math.abs(width); regionHeight = Math.abs(height); }
/** @param width The width of the texture region. May be negative to flip the sprite when drawn. * @param height The height of the texture region. May be negative to flip the sprite when drawn. */ public void setRegion (int x, int y, int width, int height) { float invTexWidth = 1f / texture.getWidth(); float invTexHeight = 1f / texture.getHeight(); setRegion(x * invTexWidth, y * invTexHeight, (x + width) * invTexWidth, (y + height) * invTexHeight); regionWidth = Math.abs(width); regionHeight = Math.abs(height); }
/** Constructs a region the size of the specified texture. */ public TextureRegion (Texture texture) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(0, 0, texture.getWidth(), texture.getHeight()); }
/** Constructs a region the size of the specified texture. */ public TextureRegion (Texture texture) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(0, 0, texture.getWidth(), texture.getHeight()); }
/** Sets the texture and sets the coordinates to the size of the specified texture. */ public void setRegion (Texture texture) { this.texture = texture; setRegion(0, 0, texture.getWidth(), texture.getHeight()); }
private void switchTexture (Texture texture) { flush(); lastTexture = texture; invTexWidth = 1.0f / texture.getWidth(); invTexHeight = 1.0f / texture.getHeight(); }
/** Sets the texture and sets the coordinates to the size of the specified texture. */ public void setRegion (Texture texture) { this.texture = texture; setRegion(0, 0, texture.getWidth(), texture.getHeight()); }
protected void switchTexture (Texture texture) { flush(); lastTexture = texture; invTexWidth = 1.0f / texture.getWidth(); invTexHeight = 1.0f / texture.getHeight(); }
private void switchTexture (Texture texture) { flush(); lastTexture = texture; invTexWidth = 1.0f / texture.getWidth(); invTexHeight = 1.0f / texture.getHeight(); }
private void drawAdjusted (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) { float invTexWidth = 1.0f / texture.getWidth(); float invTexHeight = 1.0f / texture.getHeight(); float u = srcX * invTexWidth; float v = (srcY + srcHeight) * invTexHeight; float u2 = (srcX + srcWidth) * invTexWidth; float v2 = srcY * invTexHeight; drawAdjustedUV(texture, x, y, originX, originY, width, height, scaleX, scaleY, rotation, u, v, u2, v2, flipX, flipY); }
protected void switchTexture (Texture texture) { flush(); lastTexture = texture; invTexWidth = 1.0f / texture.getWidth(); invTexHeight = 1.0f / texture.getHeight(); }
private void drawAdjusted (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) { float invTexWidth = 1.0f / texture.getWidth(); float invTexHeight = 1.0f / texture.getHeight(); float u = srcX * invTexWidth; float v = (srcY + srcHeight) * invTexHeight; float u2 = (srcX + srcWidth) * invTexWidth; float v2 = srcY * invTexHeight; drawAdjustedUV(texture, x, y, originX, originY, width, height, scaleX, scaleY, rotation, u, v, u2, v2, flipX, flipY); }
@Override public void draw (Texture texture, float x, float y) { if (!adjustNeeded) { super.draw(texture, x, y); } else { drawAdjusted(texture, x, y, 0, 0, texture.getWidth(), texture.getHeight(), 1, 1, 0, 0, 1, 1, 0, false, false); } }
@Override public void draw (Texture texture, float x, float y) { if (!adjustNeeded) { super.draw(texture, x, y); } else { drawAdjusted(texture, x, y, 0, 0, texture.getWidth(), texture.getHeight(), 1, 1, 0, 0, 1, 1, 0, false, false); } }
public void render () { Gdx.gl.glClearColor(0.4f, 0.4f, 0.4f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(rgb888, 0, 0); batch.draw(rgba8888, 60, 0); batch.draw(psRgb888, 0, 60); batch.draw(psRgba8888, psRgb888.getWidth() + 20, 60); batch.end(); }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); controller.update(); camera.update(); batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(texture, 0, 0, texture.getWidth() * 2, texture.getHeight() * 2); batch.end(); }