2
我正在嘗試開發我的第一款遊戲。加載從地圖提取的Tiles存在嚴重問題。 這是我迄今編寫的代碼,只是願意顯示第一個圖塊。從瓷磚地圖中加載子圖像
public class TileMap {
//FIELDS
public int Tilemapx;
public int Tilemapy;
private int nRows = 8;
private int nColumns = 8;
public int TileWidth = Panel.WIDTH/nColumns;
public int TileHeight = Panel.HEIGHT/nRows;
public BufferedImage EntireMap;
public BufferedImage SingleTile;
public TileMap(){
String EntireMappath = "res/Tiles.png";
try {
EntireMap = ImageIO.read(new File (EntireMappath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void drawTile(){
for (int Tilemapx = 0; Tilemapx < Panel.WIDTH/nColumns; Tilemapx++){
for (int Tilemapy = 0; Tilemapy < Pannel.HEIGHT/nRows; Tilemapy++){
BufferedImage SingleTile = EntireMap.getSubimage(100, 100, Tilemapx, Tilemapy);
}
}
}
}
,並在面板類,我想提請瓦,但似乎沒有什麼(前兩個圖像工作打算)
public void draw() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.drawImage(bg, 0, 0, getWidth(), getHeight(), null);
g.drawImage(heroImg1, hero.cordX, hero.cordY, hero.diameter, hero.diameter, null);
g.drawImage(tiles.SingleTile, 100, 200, tiles.Tilemapx, tiles.Tilemapx, null);
g.dispose();
bs.show();
}
在'TileMap.drawTile()',你聲明的局部變量'SingleTile'並指派副圖像給它。你沒有分配到「SingleTile」字段。 – johnchen902
爲了儘快提供更好的幫助,請發佈[SSCCE](http://sscce.org/)。熱鏈接到圖像或在代碼中生成一個。 –