当彼此相邻渲染图像时,Slick2D会生成视觉伪像

时间:2018-07-03 15:13:21

标签: slick2d

我正在尝试生成可缩放的彩色棋盘以用作地图。但是,即使图像彼此紧邻,也会在边缘产生伪影-黑色直线。

我尝试更改图像缩放方法,但结果更糟。

我在做什么错了?

调试应用的屏幕截图:

Map

主项目的屏幕截图:

Map Main

以下代码:

static AppGameContainer appgc;
Image tile;
float drawOffsetX;
float drawOffsetY;
float uiscale;
public float camera_x;
public float camera_y;

public TestArtifacts(String gamename) {
    super(gamename);
}

@Override
public void init(GameContainer gc) throws SlickException {
    createTile();
    uiscale = 1.0f;
    gc.getGraphics().setAntiAlias(true);
}

@Override
public void render(GameContainer gc, Graphics g) throws SlickException {
    g.translate(camera_x, camera_y);
    g.scale(uiscale, uiscale);
    for (int i = 0; i < 30; i++) {
        for (int j = 0; j < 30; j++) {
            tile.draw(20 + i * 20, 20 + j * 20, new Color(i * 60 % 255, j * 20 % 255, i * j * 10 % 255));
        }
    }
}

@Override
public void update(GameContainer gc, int i) throws SlickException {
    if (appgc.getInput().isKeyDown(Input.KEY_W)) {
        camera_y += 0.1;
    }
    if (appgc.getInput().isKeyDown(Input.KEY_S)) {
        camera_y -= 0.1;
    }
    if (appgc.getInput().isKeyDown(Input.KEY_A)) {
        camera_x -= 0.1;
    }
    if (appgc.getInput().isKeyDown(Input.KEY_D)) {
        camera_x += 0.1;
    }
}

public static void main(String[] args) {
    try {
        appgc = new AppGameContainer(new TestArtifacts("Simple Slick Game"));
        appgc.setDisplayMode(800, 600, false);
        appgc.setVSync(true);
        appgc.start();
    } catch (SlickException ex) {
        Logger.getLogger(TestArtifacts.class.getName()).log(Level.SEVERE, null, ex);
    }
}

private void createTile() {
    ImageBuffer tileMod = new ImageBuffer(100, 100);
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < 20; j++) {
            int r = 255;
            int g = 255;
            int b = 255;
            int a = 255;
            tileMod.setRGBA(i, j, r, g, b, a);
        }
    }
    tile = tileMod.getImage();
    tile.setFilter(Image.FILTER_NEAREST);
}

@Override
public void mouseWheelMoved(int change) {
    uiscale += 0.01f * change / 50;
    if (uiscale < 0.01f) {
        uiscale = 0.01f;
    }
}

0 个答案:

没有答案