We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Mouse pressed help.
Page Index Toggle Pages: 1
Mouse pressed help. (Read 581 times)
Mouse pressed help.
Dec 31st, 2009, 6:25am
 
Hey was wondering if anyone could help me, im having trouble with my code. Im fairle new to processing and i know its probably a really simple fix. I want a line moving across the screen and when the mouse is clicked an ellipse appears, the trouble im having is that the red line fills the whole screen or else when thats fixed the ellipses do not stay on the screen when there created.
Below is the code, any help would be great.
Cheers

Code:
float y = 0.0;
boolean ball = false;
void setup(){
 size(500,500);
}
void draw() {
 smooth();
 background(0);
 y = y + 1.5;
 stroke(247,15,15,200);
 strokeWeight(8);
 line(y, 0.0, y, 500);
 
   if(y>=500){
     y=0;
   }
  if(ball==true){
    fill(255);
    noStroke();
    ellipse(mouseX,mouseY,25,25);
  }
  }


void mousePressed()
{
 ball = true;

}
Re: Mouse pressed help.
Reply #1 - Dec 31st, 2009, 6:43am
 
i store the position of the circle in a x and y coordinate variable and redraw the circle every frame ... that works fine as long as you only want one circle. If you want more you probably need to use an arrayList

Code:
float y = 0.0;
boolean ball = false;
int ballX = 0;
int ballY= 0;

void setup(){
size(500,500);
}
void draw() {
smooth();
background(0);
y = y + 1.5;
stroke(247,15,15,200);
strokeWeight(8);
line(y, 0.0, y, 500);

if(y>=500){
y=0;
}
if(ball==true){
fill(255);
noStroke();
ellipse(ballX,ballY,25,25);
}
}


void mousePressed()
{
ballX = mouseX;
ballY = mouseY;
ball = true;

}
Re: Mouse pressed help.
Reply #2 - Dec 31st, 2009, 7:13am
 
Thanks so much for your help, Really helped
Page Index Toggle Pages: 1