1
\$\begingroup\$

I'm having trouble zooming in and moving my sprites. I made a simple drawing to demonstrate what happens.


No zoom:

The outline is crisp and even.

Zoomed out:

The outline is blocky and uneven.


Some lines disappear, when moving a sprite. If I use a filter, this effect improves, but the image is now blurred.

    textureParameter = new TextureLoader.TextureParameter();

    textureParameter.genMipMaps = true;
    textureParameter.minFilter = Texture.TextureFilter.MipMapLinearLinear;
    textureParameter.magFilter = Texture.TextureFilter.Linear;
    game.getManager().load(ResourcesString.image, Texture.class, textureParameter);

This is the way I deal with my camera:

//Code
private void zoomCamera(Vector3 origin, float scale){
    main.orthographicCamera.update();
    Vector3 oldUnprojection = main.orthographicCamera.unproject(origin.cpy()).cpy();
    if(scale > zoomMin) scale = zoomMin;
    if(scale < zoomMax) scale = zoomMax;
    main.orthographicCamera.zoom = scale;
    main.orthographicCamera.update();
    Vector3 newUnprojection = main.orthographicCamera.unproject(origin.cpy()).cpy();
    main.orthographicCamera.position.add(oldUnprojection.cpy().add(newUnprojection.cpy().scl(-1f)));
    main.orthographicCamera.update();
}

public void pan(float x, float y, float deltaX, float deltaY) {
    main.orthographicCamera.translate(deltaX * -2f, deltaY * 2f);
}

Why do my lines display as uneven when I zoom out, and how do I fix it?

\$\endgroup\$
  • \$\begingroup\$ Please note that this is not a forum; we do not promote discussion and you will attract downvotes of you use forum slang. Please read the help centre, and take the tour, so you know how to use this site properly. \$\endgroup\$ – Gnemlock Apr 3 '17 at 22:50
  • \$\begingroup\$ You are working with bitmap, not vector images. If you want absolutely clear lines you'd have to render all the images for all resolutions/zoom levels -- or make your peace with the tradeoffs of using filters. If you only need to draw lines and rectangles you might want to look into ShapeRenderer. \$\endgroup\$ – Wabbitseason Apr 4 '17 at 8:12
0
\$\begingroup\$

If you have a sprite that has a line that is one pixel wide and you're displaying that in a viewport that is the same as the resolution of the display/window the all is fine, but you'll get the artifacts you're describing if you (for example) zoom out so that the viewport is four times larger than the display. At that point the pixels in the sprite needs to be rendered at half their size which is impossible due to hardware limitations, instead the pixel on screen is rendered as the blend between two pixels, which is why it looks like a half line.

Setting the filtering to Nearest will combat this to a certain extent but comes with the drawback of things looking "pixely".

If what you really need us for the lines in the sprite to always be exactly 1 pixel in width, regardles of resolution, then look into using the ShapeRenderer instead.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Thank you so much for answering! I understood ..... I'll look for shapeRrenderer and polygon. \$\endgroup\$ – José Donizete Oliveira Júnior Apr 5 '17 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.