SLICK&& LWJGL闪烁问题

时间:2016-01-13 20:01:52

标签: java rendering lwjgl slick2d

渲染图块时出现闪烁问题。     渲染方法。

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

TileManager

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

}

终于Tile

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 个答案:

答案 0 :(得分:1)

使用vsync解决。

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