我正在尝试开发我的第一个游戏。我在加载从地图中提取的瓷砖时遇到了严重的问题。这是我到目前为止编写的代码,只是愿意显示第一个图块。
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);
}
}
}
}
并且,在 Panel 类中,我正在尝试绘制图块,但没有出现任何内容(前两个图像按预期工作)
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();
}