2016-01-13 93 views
3

我在渲染切片時存在閃爍問題。 渲染方法。SLICK && LWJGL閃爍問題

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

} 

最後瓷磚

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

通過使用vsync解決。

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