We are about to switch to a new forum software. Until then we have removed the registration on this forum.
As the title says, I've been stuck trying to get this piece of code to move. Any advice or help would be appreciated.
void setup() {
size(400, 400);
smooth();
background(113,181,202);
}
void draw(){
background(113,181,202);
int coordx = mouseX;
int coordy = mouseY;
if (mouseButton == LEFT){
noStroke();
fill(255, 118, 0);
ellipse (coordx, coordy, 80, 35);
coordx = coordx+1;
triangle (coordx - 60, coordy +18, coordx - 60, coordy - 18, coordx - 35, coordy);
coordx = coordx+1;
fill(0,0,0);
ellipse (coordx + 20, coordy -5, 10, 10);
coordx = coordx+1;
}
}
It needs to be drawn at the mouse cursor coordinate and move from there.
Answers
At the moment your drawing is set to be where the mouse is and is only displayed when the mouse is pressed. I made a version that initializes the drawing in the center of the screen, always displays it, and moves it slowly to the right:
Cheers, but that wasn't what I need help with. I guess I should have specified that in the original post. I need help in regards to creating the drawing upon mouse click at the cursor and having it move to the left from where it was drawn.
You have the right idea, but you should only set coordx and coordy when you press the mouse. And they need to be defined outside of any methods, that way they keep their value between method calls.