2016-01-13 97 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);