Playing a non looping gif once within an "if statement" and function.

edited October 2014 in Library Questions

Hello, essentially what I am trying to do is play a non looping gif once. Simple enough. This gif is triggered when the user's mouse is hovering over a certain area. However, what happens is the gif continues looping and looping while my mouse is over the specified area. I've tried two methods to no avail:

Method 1:

       if(dist(mouseX,mouseY,L1,L2) < 125) {
              image(nonLoopingGif,410,300);
              nonLoop();
            }

        void nonLoop(){
          nonLoopingGif.play();
        }

The above method resulted in the continuos loop. Which I assume is from the fact that every time the sketch reloads so the gif. I figured implementing a boolean would solve that, but I feel like my implementation may be wrong with method 2. And that the gif just continuously plays even without the mouse being over the specified area.

Method 2:

                       if(dist(mouseX,mouseY,cMl,cMl2) < 125) {
                          bool = true:
                        }else{
                          bool = false;
                        }

                        if(bool = true){
                          image(nonLoopingGif,410,300);          
                          nonLoop();
                        } else if (bool = false){
                          nonLoopStop();
                        }

                    void nonLoop(){
                      nonLoopingGif.play();
                    }

                      void nonLoopStop(){
                      nonLoopingGif.stop();
                    }

How can I make it so the gif plays once even while my mouse is over the specified area?

Thank you for any input. If you need more information let me know.

Answers

  • You didn't tell us which library you're using to deal w/ ".gif"!
    Nevertheless, you gotta search that library API for some method or callback which you can check whether the ".gif" made a full loop.
    W/o such support, either you gotta use another library or hack current library in order to get the additional features you wish for!

  • I'm using the "gifAnimation" library. The gif that I've created was made as a non looping gif. I think that the problem may come from that the function is continuously being called with every if statement. I'm thinking that maybe by putting the animation into an array might solve that issue.

  • edited October 2014

    AFAIK, "gifAnimation"'s play() method would start an infinite ".gif" loop.
    But you just want a round of it, not an infinite "repeat-all".
    So you dunno when to invoke stop() in order to turn the animation off once it's completed.

  • Yes! That's exactly my problem.

  • Answer ✓

    That's why in my 1st reply I've advised you to search in the library's API for something which could provide the means for that!
    If there's none, you gotta hack the library or try something else, like having an array for each ".gif" frame, so you can control its animation.

  • That's what I figured the solution would wind up being. I couldn't tell if I was missing something glaring though. I'll post up my code if I find a solution soon for future reference. Thanks.

Sign In or Register to comment.