Search code examples
libgdxdrawanglesmoothingspritebatch

Libgdx - Rotated body looks pixelated


I have this problem that is driving me nuts!

So, when I draw a boxshape body with an angle different to zero on SpriteBatch(and even on Box2DDebugRenderer happens the same), the body looks pixelated in my computer's screen. This problem persists even when I run the application in my phone. I've been searching (A LOT) about this, and I have not found anything to solve this. Most people that had similar problems (not with an angle) found solutions by changing the .setFilter to LINEAR, but that did not do anything for me.

I tried to put an image of the problem here, but apparently I need 10 points :(

So here is a link with the image :) http://postimg.org/image/xgeqttpvd/

I would really appreciate if you know the solution for this!!!!!!!!!


Solution

  • You are seeing aliasing from the edges of the rectangle of your sprite. You have two options. The first is to turn on antialiasing, which you can do like this in the desktop launcher and in the android launcher (not in the core project):

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    config.numSamples = 4; //or 2 or 8 or 16
    initialize(new MyGdxGame(), config);
    

    or on Desktop:

    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.numSamples = 4; //or 2 or 8 or 16
    new LwjglApplication(new MyGdxGame(), config);
    

    However, this will not perform very well on a phone if your game has very many sprites at all. A better way to do it is make a sprite that has a transparent border built in. Something like this (screenshot from Gimp to show transparency:

    enter image description here

    Then if you use LINEAR filtering, it will clean up the edges, because the visible edges are internal to the sprite, and not aligned with the actual polygon. Note that you will have to adjust your sprite to be slightly larger than your box2d body so it visually matches the body.