Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:12:48+00:00 2026-06-17T13:12:48+00:00

I have a shape class in which there is a method ( hitTest(int,int) )

  • 0

I have a shape class in which there is a method (hitTest(int,int)) that continuously checks if the mouse is inside its bounds or not. In another method, I keep on checking if the mouse has stayed there for more than 1 sec.
If it has, trigger a function (by notification/event) that runs animation
It it has not, then don’t trigger the animation
If it has already triggered the animation and the animation is running but the mouse leaves the area during this, trigger an interrupt function (by notification/event)

//OnLoad _initHover = false;

void update() //called continously in the application per frame
{
if(hitTest(getMouseX(), getMouseY())){
                if(!_initHover){
                    _initHover = true;
                    _hoverStartTime = getCurrentTime(); //start hover time
                    cout<<"Start hist test\n";
                }

                //If it has hovered over the video for 1.0 sec
                if((ofGetElapsedTimef() - _hoverStartTime) > 1.0){
                    cout<<"Hitting continously for 1 sec\n";
                    notificationCenter->postNotification(new AnimationStartNotification);
                }
            }
            else{
                    _initHover = false;
                    notificationCenter->postNotification(new AnimationInterruptNotification);
            }
}

The above code runs fine but there’s a logical issue I am facing while trying to use. There are multiple instances of the above Shape class and each class consequently has their update() method as well. The mouse cursor has which has animationStarthandler and animationStophandlers is a single class in the whole application.

Issue 1: So, even when one of the shape just notifies the animationStarthandler to fire, the other shape classes on which hit test is false set the animation to interrupt and the animation does not run.
Issue 2: When the hit test succeeds and the cursor has been in the area for more than 1 sec, the hit test will keep on sending the notification to start the animation (anim’s duration 1.5 sec approx.) How do I restrict the hit test to fire the animation only once and keep on firing the same animation again and again?

If in the main method of my application, I directly try to fire the animation by calling the method playAnimation in the pointer class, I get the required result. But I want to give this hover timing and animation functionality to the ShapeClass itself. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:12:50+00:00Added an answer on June 17, 2026 at 1:12 pm

    I think that you should consider adding a new boolean, which holds the information of the triggering of the animation (called in the code sample _animationTriggered). This prevents shapes that have not triggered the animation to stop it and the animation that triggered it to make it several times.

    if(hitTest(getMouseX(), getMouseY()))
    {
        if(!_initHover)
        {
            _initHover = true;
            _hoverStartTime = getCurrentTime();
            cout<<"Start hist test\n";
        }
    
        if((ofGetElapsedTimef() - _hoverStartTime) > 1.0)
        {
            if (!_animationTriggered)
            {
                cout<<"Hitting continously for 1 sec\n";
                notificationCenter->postNotification(new AnimationStartNotification);
                _animationTriggered = true;
            }
        }
    }
    else
    {
        if ( _animationTriggered )
        {
            _initHover = false;
            notificationCenter->postNotification(new AnimationInterruptNotification);
            _animationTriggered = false;
        }
    }
    

    Don’t forget to initialie this new boolean in the same place as _initHover

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an abstract parent class called shape, and that there are
In Python, say I have some class, Circle, that inherits from Shape. Shape needs
I have a base class called Geometry from which there exists a subclass Sphere
I have a Service class with a method called GetProducts(). That encapsulates business logic
I'd like to be able to call getProgram on objects which have that method,
I have a Shape class containing potentially many vertices, and I was contemplating making
Let's say we already have a hierarchy of classes, e.g. class Shape { virtual
Let me explain you my situation. I have a base class called Shape, and
I have several divs that share a common class. If one of these divs
I have a shape in Visio which is a group. The group shape can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.