We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone!
Sorry for my poor english. I'm trying to learn Processing with Shiffman's Nature of Code. I don't know why, but my object "mover" doesn't have the expected behavior. When I run the code, the object does not move in y axis, and it also start at location(width/2,0), but in the code I write width/2 and height/2 as you can see in the image.
If this question is solved in the forum, please tell me. I can't find it. Thanks.
class Mover{
PVector location;
PVector velocity;
PVector aceleration;
float topspeed;
Mover(){
location = new PVector(width/2,height/2);
velocity = new PVector(0,0);
aceleration = new PVector(-0.001,0.01);
topspeed = 10;
}
void update(){
velocity.add(aceleration);
velocity.limit(topspeed);
location.add(velocity);
}
void display(){
stroke(0);
fill(175);
ellipse(location.x,location.y,16,16);
}
void checkEdges(){
if (location.x> width) {
location.x = 0;
}
if (location.x <0 ) {
location.x = width;
}
if (location.y < 0) {
location.y = height;
}
if (location.y > height); {
location.y = 0;
}
}
}
Mover mover;
void setup(){
size(640,360);
mover = new Mover();
}
void draw(){
mover.update();
mover.checkEdges();
mover.display();
}
Answers
Remove the
;
from line 51Thanks!
Hi, here's a more compact checkEdges() method: (*)