# Resetting / Restarting Timeline animations

**URL:** <https://discourse.libcinder.org/t/resetting-restarting-timeline-animations/1907>\
**Category:** Using Cinder\
**Created:** [December 29, 2021, 8:24am UTC](https://discourse.libcinder.org/t/resetting-restarting-timeline-animations/1907 "2021-12-29T08:24:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [December 29, 2021, 8:24am UTC](https://discourse.libcinder.org/t/resetting-restarting-timeline-animations/1907/1 "2021-12-29T08:24:49Z")

</div>

Hey Embers,

I’m curious if anyone else has tried resetting or restarting animations appended to Cinder’s timeline? I’m trying to do this with no luck so far, at least not using what I thought seemed to be the right approach.

I’ve tried calling `removeTarget()` on the `Anim` object, as well as `getParent().removeSelf()`, but none of it seems to be causing the intended effect.

I’ve also not been able to find any reset/restart code in Cinder’s samples, but I’m still looking.

Anyone tried anything similar?

Cheers,  
Gazoo

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [December 29, 2021, 1:38pm UTC](https://discourse.libcinder.org/t/resetting-restarting-timeline-animations/1907/2 "2021-12-29T13:38:38Z")

</div>

It’s really just a matter of re-setting the start time.

```cpp
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Timeline.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class TweenResetApp : public ci::app::App
{
public:
    
    void draw ( ) override
    {
        gl::clear ( );
        gl::setMatricesWindow ( getWindowSize() );
        gl::translate ( getWindowCenter() );
        
        float edge = lerp ( 32.0f, 128.0f, _anim() );
        
        float r = _anim.isComplete() ? 1.0f : 0.0f;
        gl::ScopedColor color { Colorf ( r, 1.0f - r, 0 ) };
        gl::drawSolidRect( Rectf { -edge, -edge, edge, edge } );
    }
    
    void mouseDown ( MouseEvent e ) override
    {
       if ( !_tween || _tween->isComplete() )
       {
           if ( _tween ) _anim = _tween->getStartValue();
           _tween = app::timeline().apply( &_anim, 1.0f, 3.0f, EaseInOutAtan(22.0f) );
       }else
       {
           _anim = _tween->getStartValue();
           _tween->setStartTime( app::timeline().getCurrentTime() );
       }
    }
    
    Anim<float> _anim{0.0f};
    TweenRef<float> _tween;
};

CINDER_APP ( TweenResetApp, RendererGl );

```

Depending on your setup, the `Tween` may need to have `autoRemove` disabled so that the owning timeline doesn’t destroy it.

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [December 30, 2021, 1:35pm UTC](https://discourse.libcinder.org/t/resetting-restarting-timeline-animations/1907/3 "2021-12-30T13:35:44Z")

</div>

Much appreciate the response @lithium .

I was thinking there **must** be an easier way to simply undo/remove a tween. Especially because Cinder’s `ci::app::timeline().apply()` appears to do exactly that. I.e. remove any active tweens and apply the newly provided one.

For the record, I unfortunately cannot use `apply()` as my code applies consecutive animations together, and if I always trigger an `.apply()`, then it’ll wipe all the previously applied ones. I dug into libcinders code and found that it calls `removeTarget()`. I attempted to use this function on the time line and hand over a pointer to the `Anim` object, without luck still. I really have no idea why that didn’t / doesn’t work as everything points towards that being supposed to work.

I sniffed around a bit more and luckily stumbled upon the `Anim` objects `stop()` function. This does exactly that - remove any/all tweens applied to the `Anim` object.

Gazoo
