Một chút trễ ở đây, nhưng bạn luôn có thể làm điều đó một cách lập trình viên Java trò chơi làm gì, với một lớp Screen
:
public class Screen {
private int width, height;
public int[] pixels;
public Screen(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}
public void render() {
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
pixels[x + y * width] = 0xFFFFFF; //make every pixel white
}
}
}
public void clear() {
for(int i = 0; i < pixels.length; i++) {
pixels[i] = 0; //make every pixel black
}
}
}
Và sau đó trong lớp học chính của bạn:
private Screen screen;
private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
screen.clear();
screen.render();
for(int i = 0; i < pixels.length; i++) {
pixels[i] = screen.pixels[i];
}
Graphics g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
g.dispose();
bs.show();
}
Đó nên làm việc, tôi nghĩ vậy.
Thật không may java không có bất kỳ phương pháp nào để vẽ một điểm duy nhất, thay vào đó bạn phải sử dụng 'drawLine' với cùng một điểm cho cả đầu và cuối. –
@ExtremeCoders: đó là một pitty, và điều này không thêm một chi phí khủng khiếp? Tôi chỉ muốn có thể hiển thị các tập dữ liệu lớn .. –