0

処理中のオブジェクトに問題があります。コードには、2 つのオブジェクトが表示され、移動する必要があります。しかし、表示されて動いているオブジェクトが 1 つしか見えません。たぶん私が見逃しているものがあります。コードをチェックしてください。

Rule myRule;
Rule myRule1;

void setup() {
  size(200,200);
  smooth();

  //Initialize rule objects
  myRule = new Rule(0,100,1);
  myRule1 = new Rule(0,140,20);
}



void draw() {
  background(255);
  //int x1 = 0;
  //int y1 = 0;
  //Operate Rule object
  myRule.move();
  myRule.display();
  myRule1.move();
  myRule1.display();
}


class Rule {

  float x;
  float y;
  float spacing;
  float speed;

  Rule(float x1, float y1, float s1) {
    x = x1;
    y = y1;
    spacing = 10;
    speed = s1;
  }

  void move() {
    x = x + speed;
    if((x > width) || (x < 0)) {
      speed = speed * -1;
    }
  }

  //Display lines at x location
  void display() {
    stroke(0);
    fill(175);
    line(x, height/2, width/2, height/2);
  }
}
4

1 に答える 1

0

での誤字ですRule.display()。あなたはおそらく次のようなことを意味しました

line(x, y , 幅/2, 高さ/2);

于 2010-08-13T21:11:02.737 に答える