【问题标题】:Need Processing assistance. If statement需要处理协助。如果语句
【发布时间】:2015-02-23 03:09:17
【问题描述】:

有人可以帮我写代码吗?一旦它从右侧移开,我试图让正方形再次出现在窗口的左侧。我几乎拥有它,但是一旦它离开右侧,它就会突然出现在左侧。我需要帮助使它在屏幕左侧平滑显示。

这是我的代码。

float x = 0;
void setup() {
  size(200,200);
}
void draw() {
  background(255);
  drawRect();
  if(x > width+5) {
    x = 0;
 }
}
void drawRect() {
  fill(0);
  for (int i = 0; i<width; i+=15){
  rect(x +i*2,100,20,20);
}
  x = x + 1;
}

【问题讨论】:

    标签: if-statement processing void rect


    【解决方案1】:

    我真的不明白drawRect() 中的循环做了什么,但您似乎想重置x 使其绘制的形状刚好在屏幕左侧,所以是这样的:

    if (x > width+5) {
      x = -50;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多