所以这基本上就是我的代码的工作方式
class Main extends JFrame implements Runnable {
public Main() {
//init everything
}
public void start() {
running = true;
Thread thread = new Thread(this);
thread.start();
}
public void run() {
while(running) {
render();
}
}
public void render() {
Image dbImage = createImage(width, height);
Graphics dbg = dbImage.getGraphics();
draw(dbg);
Graphics g = getGraphics();
g.drawImage(dbImage, 0, 0, this);
g.dispose();
}
public void draw(Graphics g) {
for(int y=0; y < map.length; y++) {
for(int x=0; x < map.length; x++) {
g.drawImage(map.map[x + y* map.MAP_DIM], x*MAP_DIM, y*MAP_DIM, this);
}
}
}
public static void main(String... args) {
Main main = new Main();
main.start();
}
}
但什么都没有画出来,我看到的都是灰色的。有谁知道可能是什么问题?我尝试在 draw() 方法结束时执行 repaint(),但仍然没有。