public SpriteSheet(LTexture img, int tw, int th, int s, int m) { this.width = img.getWidth(); this.height = img.getHeight(); this.target = img; this.tw = tw; this.th = th; this.margin = m; this.spacing = s; }
public void setImage(LTexture image) { if (image != null || this.image != null) { boolean sizeChanged = true; if (image != null && this.image != null && image.getWidth() == this.image.getWidth() && image.getHeight() == this.image.getHeight()) { sizeChanged = false; } this.image = image; if (sizeChanged) { this.boundingRect = null; this.sizeChanged(); } } }
public void dispose() { this.isClose = true; if (texture != null) { texture.destroy(); texture = null; } }
public void dispose() { if (image != null) { image.dispose(); image = null; } if (animation != null) { animation.dispose(); animation = null; } }
public LTexture getImage(int x, int y) { checkImage(x, y); if ((x < 0) || (x >= subImages.length)) { throw new RuntimeException("SubTexture2D out of sheet bounds: " + x + "," + y); } if ((y < 0) || (y >= subImages[0].length)) { throw new RuntimeException("SubTexture2D out of sheet bounds: " + x + "," + y); } return target.getSubTexture(x * (tw + spacing) + margin, y * (th + spacing) + margin, tw, th); }
public synchronized void update() { if (isClose) { return; } if (texture == null) { texture = new LTexture(width, height, hasAlpha); } if (!texture.isLoaded()) { texture.loadTexture(); GLEx.gl10.glBindTexture(GL.GL_TEXTURE_2D, texture.getTextureID()); GLEx.gl10.glTexSubImage2D( GL.GL_TEXTURE_2D, 0, 0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); GLEx.gl10.glBindTexture(GL.GL_TEXTURE_2D, 0); } else { if (isUpdate) { GLEx.gl10.glBindTexture(GL.GL_TEXTURE_2D, texture.getTextureID()); GLEx.gl10.glTexSubImage2D( GL.GL_TEXTURE_2D, 0, 0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); GLEx.gl10.glBindTexture(GL.GL_TEXTURE_2D, 0); isUpdate = false; } } }
public void dispose() { if (target != null) { target.dispose(); target = null; } if (subImages != null) { synchronized (subImages) { for (int i = 0; i < subImages.length; i++) { for (int j = 0; j < subImages[i].length; j++) { subImages[i][j].dispose(); } } this.subImages = null; } } }
private void update() { if (subImages != null) { return; } target.loadTexture(); int tilesAcross = ((width - (margin * 2) - tw) / (tw + spacing)) + 1; int tilesDown = ((height - (margin * 2) - th) / (th + spacing)) + 1; if ((height - th) % (th + spacing) != 0) { tilesDown++; } subImages = new LTexture[tilesAcross][tilesDown]; for (int x = 0; x < tilesAcross; x++) { for (int y = 0; y < tilesDown; y++) { subImages[x][y] = getImage(x, y); } } }
public int getHeight() { if (image != null) { return image.getHeight(); } return getRectBox().height; }
public int getWidth() { if (image != null) { return image.getWidth(); } return getRectBox().width; }
public PhysicsPolygon(LTexture img) { this((Polygon) img.getShape()); }