【发布时间】:2016-05-09 19:50:30
【问题描述】:
我正在制作一个游戏,我注意到每当我使用 graphics.translate 函数和翻译后图像都会发生这种情况。
我想知道是否有办法解决这个问题,或者其他人也有同样的问题。所有这些精灵都是从 spritesheet 渲染的
编辑:翻译代码
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;
}
}
}
【问题讨论】:
-
我们可以看看你们在哪里进行翻译和渲染吗?我从未见过像这样调整绘制对象大小的 x/y 翻译。
-
@CConard96 已编辑,您只是想要翻译代码还是渲染......似乎只是在翻译图形时
-
将 g.translate() 的 x 和 y 参数转换为整数有帮助吗?这将消除任何四舍五入错误,其中瓷砖不会以完美的像素坐标结束(IE 4,而不是 4.2)。另一件要检查的事情是插值是为最近邻设置的,而不是线性的。线性插值可以拉入周围的颜色。
-
如何检查插值? @CConard96
-
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);此代码进入您的渲染循环以将其设置为最近的邻居。