在processing/java中将参数从构造函数传递给函数
我在处理某些对象时遇到问题。 代码应显示和移动两个对象。但我只看到一个物体显示和移动。也许我遗漏了什么。查看代码在processing/java中将参数从构造函数传递给函数,java,oop,constructor,class,processing,Java,Oop,Constructor,Class,Processing,我在处理某些对象时遇到问题。 代码应显示和移动两个对象。但我只看到一个物体显示和移动。也许我遗漏了什么。查看代码 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() { backgroun
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);
}
}
这是Rule.display中的一个输入错误。你的意思可能是
线条x,y,宽度/2,高度/2
代码本身在我看来很好。您使用的是哪个框架?缺少一些代码,这可能是问题所在。当我给两行着色时,我感到震惊:-//在x位置显示行void Display{stroke0;fill175;linex,y,width/2,y;我认为优先顺序存在某种排序问题。我认为高度比允许传递值的y更具体……它起作用了