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 › Ability to click on shapes/ mouse 's (N00b)
Page Index Toggle Pages: 1
Ability to click on shapes/ mouse ?'s (N00b) (Read 502 times)
Ability to click on shapes/ mouse ?'s (N00b)
Feb 6th, 2008, 12:31am
 
Hey all,

I want to be able to have multiple shapes in the screen, each being able to be clicked with a different result.

For example:

int x = 0;

void setup() {
 size(400,400);
}


void draw() {
 ellipse(10,40,40,40);
 ellipse(10,80,40,40);
 ellipse(10,100,40,40);
 ellipse(10,140,40,40);
 ellipse(10,180,40,40);
}

//If you click ellipse #1, x=x-3
//If you click ellipse #2, x=x-5
//If you click ellipse #3, x=x+2
//If you click ellipse #4, x=x+9
//If you click ellipse #5, x=0

I think that the solution might be doing a void for each one, but that requires further exploration.

Also, I haven't worked with the mouse functions that much mind you, but does the mouse constantly record a click when you hold down the button?

Much love,
TSG
Re: Ability to click on shapes/ mouse ?'s (N00b)
Reply #1 - Feb 6th, 2008, 11:25am
 
TSG,

Quote:
I want to be able to have multiple shapes in the screen, each being able to be clicked with a different result.


It's important to declare the ellipse variables as globals, instead of absolute values. You need the ellipse location, width and height to check if the mouse is over the shape.

Check out this example on buttons.


Quote:
Also, I haven't worked with the mouse functions that much mind you, but does the mouse constantly record a click when you hold down the button


Yup, the system variable mousePressed will send true as long as the mouse is pressed. If you want a single click, you should use the mousePressed() function.

Remember that the Reference and Learning sections are your friend. It's always good to check there first before posting to the forum.

cheers.

Page Index Toggle Pages: 1