Add cloud background and improve texture scaling in DiceOS
This commit is contained in:
@@ -5,6 +5,7 @@ import be.seeseemelk.diceos.system.OnStartup;
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
@@ -21,10 +22,11 @@ public class DiceOS extends ApplicationAdapter {
|
||||
private final DisplayService display;
|
||||
private final List<OnStartup> startupTasks;
|
||||
private Texture background;
|
||||
private Texture clouds;
|
||||
private Texture border;
|
||||
private Viewport vmViewport;
|
||||
private Viewport screenViewport;
|
||||
private int stretchFactor = 1;
|
||||
private int scaling = 1;
|
||||
private int offsetX = 0;
|
||||
private int offsetY = 0;
|
||||
|
||||
@@ -32,6 +34,7 @@ public class DiceOS extends ApplicationAdapter {
|
||||
public void create() {
|
||||
log.info("DiceOS starting...");
|
||||
background = new Texture("src/main/resources/background.png");
|
||||
clouds = new Texture("src/main/resources/clouds.png");
|
||||
border = new Texture("src/main/resources/border.png");
|
||||
|
||||
screenViewport = new ScreenViewport();
|
||||
@@ -52,9 +55,9 @@ public class DiceOS extends ApplicationAdapter {
|
||||
|
||||
int displayWidth = display.getWidth();
|
||||
int displayHeight = display.getHeight();
|
||||
stretchFactor = Math.min(width / displayWidth, height / displayHeight);
|
||||
offsetX = (width - (displayWidth * stretchFactor)) / 2;
|
||||
offsetY = (height - (displayHeight * stretchFactor)) / 2;
|
||||
scaling = Math.min(width / displayWidth, height / displayHeight);
|
||||
offsetX = (width - (displayWidth * scaling)) / 2;
|
||||
offsetY = (height - (displayHeight * scaling)) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +75,7 @@ public class DiceOS extends ApplicationAdapter {
|
||||
display.draw(background, x, y);
|
||||
}
|
||||
}
|
||||
display.draw(clouds, 0, 0);
|
||||
|
||||
var param = new DisplayService.Parameters();
|
||||
display.draw(border, 0, 0, param);
|
||||
@@ -88,8 +92,10 @@ public class DiceOS extends ApplicationAdapter {
|
||||
screenViewport.apply();
|
||||
display.getBatch().setProjectionMatrix(screenViewport.getCamera().combined);
|
||||
display.getBatch().begin();
|
||||
display.getBatch().draw(display.getScreenBuffer().getColorBufferTexture(),
|
||||
offsetX, offsetY, display.getWidth() * stretchFactor, display.getHeight() * stretchFactor);
|
||||
var texture = display.getScreenBuffer().getColorBufferTexture();
|
||||
var textureRegion = new TextureRegion(texture);
|
||||
textureRegion.flip(false, true);
|
||||
display.getBatch().draw(textureRegion, offsetX, offsetY, display.getWidth() * scaling, display.getHeight() * scaling);
|
||||
display.getBatch().end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DisplayService implements OnStartup {
|
||||
|
||||
@Override
|
||||
public void onStartup() {
|
||||
screenBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, getWidth(), getHeight(), false);
|
||||
screenBuffer = new FrameBuffer(Pixmap.Format.RGBA4444, getWidth(), getHeight(), false);
|
||||
screenBuffer.getColorBufferTexture().setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
|
||||
batch = new SpriteBatch();
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class DisplayService implements OnStartup {
|
||||
public static class Parameters {
|
||||
public final static Parameters DEFAULT = new Parameters();
|
||||
|
||||
public boolean flipX;
|
||||
public boolean flipY;
|
||||
public boolean flipX = false;
|
||||
public boolean flipY = false;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/main/resources/clouds.png
Normal file
BIN
src/main/resources/clouds.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 280 KiB |
Reference in New Issue
Block a user