I made a game using Slick2d, and after building it, I decided that I wanted to put in on mobile devices(Android specifically). After copying the classes over and modifying Images to Textures(I was using Images in Slick2d), I noticed that my entire game layout was upside down. I used the “batch.setProjectionMatrix(camera.combined);” statement flip everything horizontally, but my images were then upside down. So I flipped every image horizontally. Everything seems to work fine, except that I can not get it to stretch the screen to fit my Android phone’s screen.
This is the code from the main class…
public class Game implements ApplicationListener {
private SpriteBatch batch;
private Texture permBlock, characterR;
OrthographicCamera camera;
private static final int VIRTUAL_WIDTH = 100;
private static final int VIRTUAL_HEIGHT = 200;
private Rectangle viewport;
public void create() {
batch = new SpriteBatch();
characterR = new Texture(Gdx.files.internal("data/CharacterRight.png"));
permBlock = new Texture(Gdx.files.internal("data/PermBlock.png"));
camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
Levels.Start();
}
public void dispose() {
batch.dispose();
characterR.dispose();
permBlock.dispose();
}
public void render() {
camera.update();
Gdx.gl.glViewport((int) viewport.x, (int) viewport.y, (int) viewport.width, (int) viewport.height);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
Gdx.gl.glClearColor(0, 0, 0.0f, 1.02f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
for (int c = 0; c < PermBlock.getTotAmount(); c++) {
batch.draw(permBlock, PermBlock.getPosX(c), PermBlock.getPosY(c), 26, 26, 0, 0, 26, 26, false, true);
}
batch.draw(characterR, Character.getPosX(), Character.getPosY(), 8, 50, 0, 0, 8, 50, false, true);
batch.end();
//Input Keys were removed for my post
}
public void resize(int width, int height) {
camera.setToOrtho(true, width, height);
Vector2 newVirtualRes= new Vector2(0f, 0f);
Vector2 crop = new Vector2(width, height);
newVirtualRes.set(Scaling.fill.apply((float)VIRTUAL_WIDTH, (float)VIRTUAL_HEIGHT, (float)width, (float)height));
crop.sub(newVirtualRes);
crop.mul(.25f);
viewport = new Rectangle(crop.x, crop.y, newVirtualRes.x, newVirtualRes.y);
}
public void pause() {
}
public void resume() {
}
}
I want my game to keep the same ratio(100x200) but fill the screen on the X-axis. I’ve tried Scaling.stretch, Scaling.fit, Scaling.fill, Scaling.fillY…none seem to change anything.
How can I fit it to the screen?