无法摆脱处理草图中的视觉伪影


int numFrames = 5; //Number of animation frames
int frame = 0;
PImage[] images = new PImage[numFrames]; //Image array
void setup() 
{
    size(800, 800);
    background(180, 180, 180);
    frameRate(15); //Maximum 30 frames per second 
}
void draw() 
{
    images[0] = loadImage("Ayylmfao.0001.png");
    images[1] = loadImage("Ayylmfao.0002.png");
    images[2] = loadImage("Ayylmfao.0003.png");
    images[3] = loadImage("Ayylmfao.0004.png");
    images[4] = loadImage("Ayylmfao.0005.png");
    frame++;
        if (frame == numFrames) 
        {
            frame = 0;
        }
    image(images[frame], 0, 0);
}

所以我的问题是这样的:当我尝试运行这个动画时,我不断从以前的帧中获得伪影。我正在使用数组将图像存储在动画中,因为我正在尝试练习使用数组。

动画是一个眨眼的眼球。问题是,当它闪烁时,所有以前的帧都被绘制过来。眼球的虹膜消失,眼球开始收集前几帧的伪影。

正如凯文指出的那样,你不应该一遍又一遍地加载图像,每秒多次draw()。您应该在setup()加载它们一次,然后draw()渲染它们:

int numFrames = 5; //Number of animation frames
int frame = 0;
PImage[] images = new PImage[numFrames]; //Image array
void setup() 
{
    size(800, 800);
    background(180, 180, 180);
    frameRate(15); //Maximum 30 frames per second 
    images[0] = loadImage("Ayylmfao.0001.png");
    images[1] = loadImage("Ayylmfao.0002.png");
    images[2] = loadImage("Ayylmfao.0003.png");
    images[3] = loadImage("Ayylmfao.0004.png");
    images[4] = loadImage("Ayylmfao.0005.png");
}
void draw() 
{
    frame++;
        if (frame == numFrames) 
        {
            frame = 0;
        }
    image(images[frame], 0, 0);
}

最新更新