Swift:类似于Java中的双缓冲
在Java中,我可以将像素数据写入图像,然后通过重写的方法(paint和paintComponent)将其打印到屏幕上。我可以通过更新图像并调用refresh()来轻松刷新屏幕,这将调用paint/paintComponent循环 我想在swift(3)中用UIImage来实现这一点。我可以更新图像,但我不知道如何重复将图像投影到屏幕上,打印屏幕,并在需要刷新屏幕时重复 首先,哪种类型的swift项目(单视图应用程序、游戏等)最适合反复刷新屏幕 第二,我如何在Swift中创建一个(受监管的)循环,每隔一段时间刷新一次屏幕 在java中,这看起来像(在扩展框架的类中):Swift:类似于Java中的双缓冲,java,swift,animation,view,graphics,Java,Swift,Animation,View,Graphics,在Java中,我可以将像素数据写入图像,然后通过重写的方法(paint和paintComponent)将其打印到屏幕上。我可以通过更新图像并调用refresh()来轻松刷新屏幕,这将调用paint/paintComponent循环 我想在swift(3)中用UIImage来实现这一点。我可以更新图像,但我不知道如何重复将图像投影到屏幕上,打印屏幕,并在需要刷新屏幕时重复 首先,哪种类型的swift项目(单视图应用程序、游戏等)最适合反复刷新屏幕 第二,我如何在Swift中创建一个(受监管的)循环
static int width=1440;
静态内部高度=900;
私有缓冲图像画布;
静态颜色[][]RGBMap=新颜色[宽度][高度];
公共组件(图形g){
超级组件(g);
图形2d g2=(图形2d)g;
g2.挫折背景(颜色:白色);
g2.clearRect(0,0,宽度,高度);
g2.drawImage(this.canvas,null,null);
油漆();
}
公共空间涂料(){
int i=0;
while(i
static int width = 1440;
static int height = 900;
private BufferedImage canvas;
static Color[][] RGBMap = new Color[width][height];
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.drawImage(this.canvas, null, null);
paint();
}
public void paint() {
int i = 0;
while (i < width) {
int t = 0;
while (t < height) {
this.canvas.setRGB(i, t, RGBMap[i][t].getRGB());
t++;
}
i++;
}
//Refreshes RGBMap
iterate();
repaint();
}