Support repeating background texture

This commit is contained in:
drdev
2014-03-29 03:14:15 +00:00
parent f82e8b277c
commit 4f58ecd08d
2 changed files with 32 additions and 7 deletions

View File

@@ -594,6 +594,19 @@ public class Forge implements ApplicationListener {
batch.draw(image, adjustX(x), adjustY(y, h), w, h);
}
public void drawRepeatingImage(Texture image, float x, float y, float w, float h) {
startClip(x, y, w, h);
int tilesW = (int)(w / image.getWidth()) + 1;
int tilesH = (int)(h / image.getHeight()) + 1;
batch.draw(image, adjustX(x), adjustY(y, h),
image.getWidth() * tilesW,
image.getHeight() * tilesH,
0, tilesH, tilesW, 0);
endClip();
}
public void drawRotatedImage(Texture image, float x, float y, float w, float h, float originX, float originY, float rotation) {
batch.draw(image, adjustX(x), adjustY(y, h), originX - x, h - (originY - y), w, h, 1, 1, rotation, 0, 0, image.getWidth(), image.getHeight(), false, false);
}

View File

@@ -3,17 +3,21 @@ package forge.assets;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import forge.Forge.Graphics;
public enum FSkinTexture implements FImage {
BG_TEXTURE("bg_texture.jpg"),
BG_MATCH("bg_match.jpg");
private final String filename;
private Texture texture;
BG_TEXTURE("bg_texture.jpg", true),
BG_MATCH("bg_match.jpg", false);
FSkinTexture(String filename0) {
private final String filename;
private final boolean repeat;
private Texture texture;
FSkinTexture(String filename0, boolean repeat0) {
filename = filename0;
repeat = repeat0;
}
public void load(String preferredDir, String defaultDir) {
@@ -42,6 +46,9 @@ public enum FSkinTexture implements FImage {
}
}
}
if (repeat) {
texture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
}
}
@Override
@@ -56,6 +63,11 @@ public enum FSkinTexture implements FImage {
@Override
public void draw(Graphics g, float x, float y, float w, float h) {
g.drawImage(texture, x, y, w, h);
if (repeat) {
g.drawRepeatingImage(texture, x, y, w, h);
}
else {
g.drawImage(texture, x, y, w, h);
}
}
}