嗨,我是编程的新手,虽然我正在尝试做一个练习,但这个错误加速了,我不知道这意味着什么,以及如何解决它。 这是在我尝试复制后,在processing.js库中的一个例子,并没有那么顺利。
Mover mover;
void setup(){
size (600,600);
mover = new Mover();
}
void draw(){
mover.update();
mover.display();
mover.checkEdges();
}
class Mover {
// position, velocity, and acceleration
PVector position;
PVector velocity;
PVector acceleration;
// Mass is tied to size
float mass;
Mover(float m, float x, float y) { //<<<the error occurs here
mass = m;
position = new PVector(x, y);
velocity = new PVector(0, 0);
acceleration = new PVector(0, 0);
}
// Newton's 2nd law: F = M * A
// or A = F / M
void applyForce(PVector force) {
// Divide by mass
PVector f = PVector.div(force, mass);
// Accumulate all forces in acceleration
acceleration.add(f);
}
void update() {
// Velocity changes according to acceleration
velocity.add(acceleration);
// position changes by velocity
position.add(velocity);
// We must clear acceleration each frame
acceleration.mult(0);
}
// Draw Mover
void display() {
stroke(255);
strokeWeight(2);
fill(255, 200);
ellipse(position.x, position.y, mass*16, mass*16);
}
// Bounce off bottom of window
void checkEdges() {
if (position.y > height) {
velocity.y *= -0.9; // A little dampening when hitting the bottom
position.y = height;
}
}
}
答案 0 :(得分:0)
我在代码中看到的唯一问题是你的Mover
构造函数有三个参数,但是你没有在这一行中给出任何参数:
mover = new Mover();
所以我先修复那个错误。如果您仍然遇到问题,请更准确地了解您如何编译和运行此代码。你在使用Processing编辑器吗?哪个版本?在哪一步确实出现错误?