image sequence play from first frame when mouse over

Hello,

I was working on my project with images sequences, how can each image sequence only play from the first frame ( start to play ) when mouse over it ? I was using the addon ofxMSAInteractiveObject and ofxImageSequence. Thanks a lot.

here is the code of MyTestSeq.h

  
  
#pragma once  
  
#include "ofxMSAInteractiveObject.h"  
#include "ofxImageSequence.h"  
  
  
class MyTestSeq : public ofxMSAInteractiveObject {  
public:  
  
    ofxImageSequence sequence;  
    //bool playing;  
    float rot;  
    float scale;  
  
	void setup() {  
  
		enableMouseEvents();  
		enableKeyEvents();  
  
		sequence.loadSequence("bloom_a/bloom_a", "png", 1, 20, 2);  
	    sequence.preloadAllFrames();	//this way there is no stutter when loading frames  
	    sequence.setFrameRate(10); //set to ten frames per second sequence.  
	    scale = ofRandomuf()*1.2;  
  
        //playing = false; //controls if playing automatically, or controlled by the mouse  
  
	}  
  
  
	void exit() {  
	}  
  
  
	void update() {  
  
	}  
  
  
	void draw() {  
  
	    ofSetRectMode(OF_RECTMODE_CENTER);  
  
	    glPushMatrix();  
        glTranslatef (width/2 + x, height/2 + y, 0);  
        glRotatef (rot,0,0,1);  
        glScalef(scale,scale,1);  
  
	    if(isMouseOver()){  
  
	    sequence.getFrameForTime(ofGetElapsedTimef())->draw(0,0);  
  
	    }  
  
	    glPopMatrix();  
  
	}  
  

The problem is that ofGetElapsedTimef() is going to increase the entire time that your application is running, very quickly going past the length of your sequence. I think what you want is something more like:

  
if(isMouseOver) {  
mouseOverTimeTotal += frameStep; // frame step = 1/60 or 1/30?  
sequence.getFrameForTime(mouseOverTimeTotal)->draw(0,0);   
}  

or

  
if(isMouseOver) {  
mouseOverTimeTotal += 1; // frame  
sequence.getFrame(mouseOverTimeTotal)->draw(0,0);   
}  

Hello joshua,

Thanks a lot for replying my question, sorry as I’m quite new to programming, so quite a lot I don’t know. When I tried the code you had showed me. The sequence will show only the first frame but without running the whole sequence.

So I check again with the original code of the addon ofxImageSequence:

here is the code :

  
  
void testApp::setup(){  
	//File format for the example frames is  
	//frame01.png  
	//this creates a method call where the parameters  
	//prefix is frame, file type is png, from frame 1 to 11, 2 digits in the number  
	sequence.loadSequence("frame", "png", 1, 11, 2);  
	sequence.preloadAllFrames();	//this way there is no stutter when loading frames  
	sequence.setFrameRate(10); //set to ten frames per second for Muybridge's horse.  
  
	playing = false; //controls if playing automatically, or controlled by the mouse  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
  
  
	if(playing){  
		//get the frame based on the current time and draw it  
		sequence.getFrameForTime(ofGetElapsedTimef())->draw(0,0);  
	}  
	else {  
		//get the sequence frame that maps to the mouseX position  
		float percent = ofMap(mouseX, 0, ofGetWidth(), 0, 1.0, true);  
  
		//draw it.  
		sequence.getFrameAtPercent(percent)->draw(0, 0);  
	}  
}  
  
  

And I think my question is in the void testApp::draw() part, how can I get the frame based on the first frame of the animation sequence but not the current time. ( Every time I placed the mouse on the position where has a sequence, the sequence will then appear but not running from the first frame, it seems that it’s keep running a loop and display from the current frame when the time I place the mouse.)

  
  
void testApp::draw(){  
  
  
	if(playing){  
		//get the frame based on the current time and draw it  
		sequence.getFrameForTime(ofGetElapsedTimef())->draw(0,0);  
	}