-1

I am making a game and I noticed whenever I use the graphics.translate function and after the translate this happens to the images.

Before Translation Before translation

After Translation After Translation

I was wondering if there is anyway to fix that or anyone else has the same issue. All these sprites are rendered from a spritesheet

EDIT: Translate code

public void translate(Graphics g, GameContainer container, int delta) {
        g.translate(((container.getWidth() / 2) - this.x), ((container.getHeight() / 2) - this.y));
    }

    public void update(GameContainer container, int type){
        if (type == 0) {
            x = p.getX(); //p is the player
            y = p.getY();
        } else if (type == 1) {
            x = player.x;
            y = player.y;
        }

        if (offset) {
            if (this.x - container.getWidth() / 2 < offsetMin[0]) {
                x = offsetMin[0] + container.getWidth() / 2;
            } else if (this.x + container.getWidth() / 2 > offsetMax[0]) {
                x = offsetMax[0] - container.getWidth() / 2;
            }

            if (this.y - container.getHeight() / 2 < offsetMin[1]) {
                y = offsetMin[1] + container.getHeight() / 2;
            } else if (this.y + container.getHeight() > offsetMax[1]) {
                y = offsetMax[1] - container.getHeight() / 2;
            }
        }
    }
user2580555
  • 329
  • 2
  • 4
  • 13
  • May we see where you do the translation and rendering? I have never seen an x/y translation resize drawn objects like that. – CConard96 May 11 '16 at 21:37
  • @CConard96 Edited, did you just want the translate code or the rendering aswell.. It seems to just be when the graphics gets translated – user2580555 May 11 '16 at 21:45
  • Does it help if you cast the x and y parameters for g.translate() to ints? That would eliminate any rounding errors where tiles don't end up on perfect pixel coords (IE 4, not 4.2). The other thing to check is that interpolation is set for nearest neighbor and not linear. Linear interpolation can pull in surrounding colors. – CConard96 May 11 '16 at 21:57
  • How would I check the interpolation? @CConard96 – user2580555 May 11 '16 at 22:23
  • GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); This code goes in your render loop to set it to nearest neighbor. – CConard96 May 11 '16 at 22:26
  • Thank you, casting it as an int worked. Thank you very much! @CConard96 – user2580555 May 11 '16 at 22:34

1 Answers1

1

Try casting the x and y parameters for g.translate() to ints. That would eliminate any rounding errors where tiles don't end up on perfect pixel coords (IE 4, not 4.2).

Moved answer from comments to answer so it can be marked as accepted by OP

CConard96
  • 874
  • 1
  • 7
  • 18