Hi JGO!
I’m currently working on a simple side-scrolling game for my software engineering class. I’ve been working on the graphics lately and being able to resize the screen while having the aspect ratio stay the same. Everything is working fine with the resizing, but once I begin resizing it, I get weird lines between my tiles. Here’s a picture:
I checked out this thread below which seemed similar, but most of the proposed solutions did not seem to work for me.
I tried rounding the camera coordinates before sending it to the SpriteBatch but that didn’t help. I’m loading the tiles from a single Texture and splitting them up into an array of TextureRegions, but the pink color of the line artifact is from a neighboring tile to the dark purple one seen here. If I change the pink tile to gray, sure enough the line artifact changes gray. I tried loading the texture with different filters but nothing worked. I feel like it must be something with the texture though because of the way its sampling the texture outside of its region.
Now that I think about it, I haven’t really seen many games allow you to stretch the window to whatever size you want. Is this why perhaps? Maybe I should just have a couple different scales that are stable, to scale the resolution up by? Here is the resize method from my Game class (implementing ApplicationListener from gdx). The code is taken off a tutorial I found, I can try to find the link for it if anyone wants.
public void resize(int width, int height) {
float aspectRatio = (float) width / (float) height;
float scale = 1f;
Vector2 crop = new Vector2(0f, 0f);
if (aspectRatio > Screen.ASPECT_RATIO) {
scale = (float) height / (float) Screen.SCREEN_H;
crop.x = (width - Screen.SCREEN_W * scale) / 2f;
} else if (aspectRatio < Screen.ASPECT_RATIO) {
scale = (float) width / (float) Screen.SCREEN_W;
crop.y = (height - Screen.SCREEN_H * scale) / 2f;
} else {
scale = (float) width / (float) Screen.SCREEN_W;
}
Gdx.gl.glViewport((int) crop.x, (int) crop.y, (int) (Screen.SCREEN_W * scale), (int) (Screen.SCREEN_H * scale));
}
Thanks for your help!
-Bukky