Animation not working on second object

Hi everyone,
I have a very simple object that draw a circle that shrinks in time.
The shrink animation is just a function that diminish the radius value to 0.

I am adding the object to the window using vectors.

I have a method that simply add a new circle, something like this:

void  ofApp::createNewCircle(){
Circle circle;
circle.setup();
groupOfCircles.push_back(circle);
}

the first circle simply draw and shrink.
the second one just start at maximum radius and the disappear.
basically it gos straight to zero radius.

i do not understand why, because i’ve tried to add multiple circle with different radius and everything works well, but with this variable to 0 it does not reset, even if is a new object.

Thanks for the answer.

Hi There
if you can post some more (or all) of the code then perhaps we can find the bug - it might be that you are setting a variable and not resetting it for other circles or something similar…

1 Like

This is the parte of my circle class, i’m using an external easing function

void Circle::setup(){
    startRadius = ofRandom(20, 200);
    radius = startRadius;
    x = ofRandom(startRadius, ofGetWidth()-startRadius);
    y = ofRandom(startRadius, ofGetHeight()-startRadius);
    
}

void Circle::update(){
    float t = ofClamp(ofGetElapsedTimef() / 2, 0, 1);
    float v = ofxEasingFunc::Cubic::easeInOut(t); 
    int val = ofMap(v, 1, 0, 0, startRadius);
    radius = val;
}

void Circle::draw(){
    ofSetCircleResolution(100);
    ofDrawCircle(x, y, radius);
}

This is in my ofApp

void ofApp::setup(){
    createNewCircle();
}

void ofApp::update(){
    for (int i = 0; i<groupOfCircles.size(); i++) {
        groupOfCircles[i].update();
    }
}

void ofApp::draw(){
    for (int i = 0; i<groupOfCircles.size(); i++) {
        groupOfCircles[i].draw();
    }
}

void  ofApp::createNewCircle(){
   Circle circle;
   circle.setup();
   groupOfCircles.push_back(circle);
}

void ofApp::mousePressed(int x, int y, int button){
    createNewCircle();
}

thanks for your time

All of your circles are using this function ofGetElapsedTimef() which measure the time the software is running. you should count time individually in your Circle object to make it work as desired.

something like:

float startTime, elapsedTime;
//setup
startTime = ofGetElapsedTimef(); 

//update
elapsedTime = ofGetElapsedTimef() - startTime;
1 Like

Thanks, I misunderstood the functionality of ofGetElapsedTimef().
Now it works.