ofRectangle inside() event trigger

Hi there !

Glad to write my first post in this warm community :slight_smile:

I’m kind of stuck on a pretty simple issue regarding update loop and event trigger.
Basically, I need to send an OSC message and updating a Tween (not using ofxEasing here) only when the mouse collide a rectangle.

So far I’ve used something similar to this inside the update function :

if (rect.inside(mouseX, mouseY)) {
isInside = true;

if (isInside) {
ofxOscMessage m;

unsigned delay = 0;
unsigned duration = 1000;

How would you go to trigger an event only once when the mouse cursor is inside an ofRectangle ?

Thanks in advance :smile_cat:

All you need to do is to check if your mouse coordinates are inside the limits defined by your rectangle. In pseudocode:

if((mouse.x >= leftBorderOfTheRect && mouse.x <= rightBorderOfTheRect ) &&
   (mouse.y >= topBorderOfTheRect && mouse.y <= bottomBorderOfTheRect )
) {
   inside = true;

Regarding events, have a look in the example folder.

that’s it !

sorted it out by triggering my events according to the state of the tween, will check the example folder to know a proper way to do it though, thanks !