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 › mousePressed problem
Page Index Toggle Pages: 1
mousePressed problem (Read 549 times)
mousePressed problem
Mar 27th, 2010, 1:00am
 
The code I have is not very complicated because I'm new to this so I'm sure there's a simpler way to do this I just can't figure it out. My problem is that my program will run but my mousePressed code won't do anything. What I want is for my text to show up in the rectangles I've created when you click in them but nothing's happening. Any ideas?


float [] births = {
3.49, 3.61, 3.68, 3.63, 3.66, 3.76, 3.73, 3.82, 3.90,
4.02, 4.17, 4.11, 4.08,4.03, 3.97, 3.89, 3.89, 3.88, 3.94, 3.95, 4.05,
4.02, 4.02, 4.08, 4.11, 4.13 };
float [] year = { 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987,
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005 };

PFont ff;


void setup ()
{
 size(400, 800);
 background( 245, 255, 134);
 smooth();
 ff = loadFont ("ff.vlw");
 stroke(0);
 rect(.25*width, .038*height, .5*width, .939*height);
 line(.5*width, .038*height, .5*width,.975*height);
 for( int i=0; i<year.length; i++)
 {
   strokeWeight(1);
   stroke(0);
   float y1 =(i+1)*((height)/(births.length+1));
   line(.25*width,y1,.75*width,y1);
 

 }  
}

void draw ()
{
 mousePressed ();
}

void mousePressed()
{
 for(int i=0; i<year.length; i++)
 {
   if(dist(25*width,.038*height, mouseX, mouseY)<720.8)
   {
     textFont(ff);
     strokeWeight(1);
     textAlign(LEFT);
     stroke(0,0,255);
     text("1979", .3*width,2*(.038*height));

I have more lines of text after this one, a lot more
Re: mousePressed problem
Reply #1 - Mar 27th, 2010, 1:08am
 
Try removing mousePressed() from within draw()... Smiley
I'm pretty sure you should not call it there...
Re: mousePressed problem
Reply #2 - Mar 27th, 2010, 3:11am
 
at least not like in void mousepressed()
http://processing.org/reference/mousePressed_.html


you can still use mousePressed though
http://processing.org/reference/mousePressed.html
Page Index Toggle Pages: 1