0

I am making a game where player sees the game from top. (GTA2 type of viewing) Thus camera follows the player as he moves anywhere in the map. However as the camera position changes, the images shake very slightly.

I have already checked the x and y variables of the shaking objects and even when they are constant, isolated from the other components of the game, I have the same issue. But it is gone when I test the game in fullscreen, so probably libgdx somehow rounds the objects position when the camera dimensions are small. Another clue is that when I use images with very thin lines (like image of a net), only some of the lines appear depending on camera position (it is again solved when I use fullscreen). So the solution is probably something like

font.setUseIntegerPositions(false);

in terms of SpriteBatch.

The camera dimensions and initialization is as follows:

public static int cameraWidth = 620;
public static int cameraHeight = 320;
...
camera = new OrthographicCamera();
camera.setToOrtho(false, cameraWidth, cameraHeight);


//---inside the render--
//Update the Time Variable
stateTime += Gdx.graphics.getDeltaTime();
//Clear the Screen
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
//Set the Camera
final float cameraMaxY = mapHeight+menuHeight-cameraHeight/2;
final float cameraMinY = cameraHeight/2;
final float cameraMovableY = cameraMaxY - cameraMinY;
final float cameraMaxX = mapWidth-cameraWidth/2;
final float cameraMinX = cameraWidth/2;
final float cameraMovableX = cameraMaxX - cameraMinX;
camera.position.set(cameraMinX+cameraMovableX*cameraFollow.body.getPosition().x/mapWidth,cameraMinY+cameraMovableY*cameraFollow.body.getPosition().y/mapHeight,0);
camera.update();

where cameraFollow is just a variable that represents an object in physics world. I am sure camera.position.set algorithm is not the cause. What can I do to make libgdx draw everything in their exact positions without any approximations?

ozgeneral
  • 6,079
  • 2
  • 30
  • 45
  • 2
    SpriteBatch does not round off positions. Sounds like you are using the wrong TextureFilter (nearest). You probably want to use (MipMapLinearNearest, Linear). – Tenfour04 Feb 11 '15 at 16:54
  • I use texture.setFilter(TextureFilter.Linear,TextureFilter.Linear); – ozgeneral Feb 14 '15 at 22:18
  • Just converted it to texture.setFilter(TextureFilter.Nearest, TextureFilter.Linear); but that didn't help – ozgeneral Feb 14 '15 at 22:23
  • 2
    You're not going to try the one I suggested? :) Your description sounds exactly like what it looks like if you don't use mip mapping and the graphics are being shrunk. – Tenfour04 Feb 15 '15 at 00:03
  • 1
    Oh I didn't know that MipMapLinearNearest is a thing, I thought you suggested to use Mip, Map, Linear or Nearest :D Thanks a lot that fixed it! – ozgeneral Feb 15 '15 at 17:35

0 Answers0