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 & HelpPrograms › How to catch to sit a mark
Page Index Toggle Pages: 1
How to catch to sit a mark (Read 553 times)
How to catch to sit a mark
Oct 24th, 2007, 4:54am
 
How to catch to sit a mark which the picture of dynamic state ?
Re: How to catch to sit a mark
Reply #1 - Oct 24th, 2007, 9:16am
 
are you asking how to catch when an image is clicked? otherwise please try again ..
Re: How to catch to sit a mark
Reply #2 - Oct 25th, 2007, 3:02am
 

Yes,I ask how to catch when an image is clicked,but the image is flowing. I want to make sure its position.
Re: How to catch to sit a mark
Reply #3 - Oct 25th, 2007, 7:06am
 
hi. use a custom class containing your image and its position on the screen :

Code:
class MovingImage {

PImage img; // image
int x = 0; // position
int y = 0;

// constructor
MovingImage(PImage img) {
this.img = img;
}

// method to display the image on the screen
void draw() {
image(img, x, y);
}

// method to test if the cursor is over the image
boolean isUnderMouse() {
if (mouseX < x || mouseX > x + img.width) return false;
if (mouseY < y || mouseY > y + img.height) return false;
return true;
}
}


and when the mouse is pressed, test if the cursor was over your moving image :

Code:
void mousePressed() {
if (myMovingImage.isUnderMouse())
println("the image was clicked");
}
Re: How to catch to sit a mark
Reply #4 - Oct 25th, 2007, 7:54am
 
Thank you! You gave me inspire.
Page Index Toggle Pages: 1