【问题标题】:Unable to get rid of visual artifacts in Processing sketch无法摆脱处理草图中的视觉伪影
【发布时间】:2016-11-17 20:46:11
【问题描述】:
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() 函数加载它们。

标签: arrays animation processing visual-artifacts


【解决方案1】:

正如 Kevin 所指出的,您不应该在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);
}

【讨论】:

  • 所以我想通了。背景仅在设置中使用,然后被绘制。不过感谢您提供有关阵列的提示。
猜你喜欢
  • 2010-11-09
  • 2012-09-20
  • 2020-03-24
  • 1970-01-01
  • 1970-01-01
  • 2015-02-09
  • 1970-01-01
  • 2011-12-16
  • 1970-01-01
相关资源
最近更新 更多