首页 > 解决方案 > 我的 if 条件不适用于处理语言

问题描述

我正在为我的作业处理语言。这是一部动画。动画对象(一个球)需要从上到下。我已将变量声明为float x,y. 每当我设置 if 条件以将其大小增加 1 时,但它并没有移动一英寸。

float x;
float y;

size(600, 400)

x = 0.4*width/8;
y = 0.4*height/8;


ellipse( width/2, x, 0.8*width/8, 0.8*width/8);
ellipse( y, height/2, 0.8*height/8, 0.8*height/8);



if(x < height){
    x = x+1;
}

if(y < width){
   y=y+1;
}

我期待输出 - 位于顶部的球向下移动并停在底部,左侧球向右移动并停在最右边的点。

标签: if-statementprocessing

解决方案


您在“静态模式”下使用处理,这意味着您的代码运行一次然后完成。到达代码末尾后没有任何反应。

要利用 Processing 的 60 FPS 渲染循环,您需要指定setup()draw()函数。像这样的东西:

float circleY;

void setup(){
  size(200, 200);
  circleY = height/2;
}

void draw(){
  background(200);
  ellipse(100, circleY, 20, 20);

  circleY = circleY + 1;
}

无耻的自我推销:是Processing中的动画教程。


推荐阅读