图像怪异与流畅的2D图形翻译

goqiplq2  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(181)

我正在做一个游戏,我注意到每当我使用graphics.translate函数时,在翻译之后,这种情况就会发生在图像上。
翻译前

翻译后

我想知道是否有任何方法可以解决这个问题,或者其他人也有同样的问题。所有这些精灵都是从精灵表渲染的
编辑:翻译代码

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;
            }
        }
    }
j8ag8udp

j8ag8udp1#

尝试将g.translate()的x和y参数强制转换为int。这将消除任何舍入错误,瓷砖没有结束在完美的像素坐标(即4,而不是4.2)。
将答案从注解移动到答案,以便可以将其标记为op接受

相关问题