SLICK && LWJGL 闪烁问题

3
我在渲染瓷砖时遇到了闪烁问题。 渲染方法。
int tileSize = TileManager.tileSize;

    for(int y = 0 ; y < mapHeight ; y++){
        for(int x = 0 ; x < mapWidth ; x++){
            TileManager.tiles[tileIDs[y][x]].render(x * tileSize + xOffset, y * tileSize + yOffset, g);
        }
    }

瓷砖管理器
public static Tile[] tiles = new Tile[256];

public static final int tileSize = 32;

public static void loadTiles(String path){

    Image tileSet = GeneralUtils.getImage(path);

    int row = (int)Math.floor(tileSet.getWidth() / tileSize);
    int col = (int)Math.floor(tileSet.getHeight() / tileSize);

    for(int y = 0 ; y < col ; y++){
        for(int x = 0 ; x < row ; x++){
            tiles[x + y * row] = new Tile(tileSet.getSubImage(x * tileSize, y * tileSize, tileSize, tileSize));
        }
    }

}

最后的瓷砖
private Image tileImage;

public Tile(Image tileImage){
    this.tileImage = tileImage;
}

public void render(int xPix, int yPix, Graphics g){
    g.drawImage(tileImage, xPix, yPix);
}

如果我像这样渲染,就不会出现闪烁。我不明白为什么?
img = new Image("Res/blabla.png");
----------------------------------------------------
int tileSize = TileManager.tileSize;

    for(int y = 0 ; y < mapHeight ; y++){
        for(int x = 0 ; x < mapWidth ; x++){
            g.drawImage(img, x * tileSize + xOffset, y * tileSize + yOffset);
        }
    }

有什么不同之处?
1个回答

1

通过使用垂直同步解决。

private static AppGameContainer gameApp;
gameApp.setVSync(true);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接