Is this the fastest way to clear a screen? Storing a “cleared” screen in another array and System.arraycopying it into the current pixel array?
public final class Display {
private int[] clearedPixels;
int[] pixels;
int width;
int height;
private int size;
public Display(int w, int h) {
this.width = w;
this.height = h;
pixels = new int[w * h];
clearedPixels = new int[w * h];
size = w * h;
}
public void setClearColor(int color) {
for (int i = 0; i < clearedPixels.length; i++) {
clearedPixels[i] = color;
}
}
public void clear() {
System.arraycopy(clearedPixels, 0, pixels, 0, size);
}
}