ID:1742659
 
(See the best response by Mightymo.)
How do you force stop an animation so you can re-run it from the very beginning?

My guess would be to add it to an object, run it off of it, and delete that object to stop the animate then redo it. This is meant for spamming an animate even if it isn't finished yet.
By passing the object into the animation, it will overwrite the current animations.

animate(src)

will clear the current animation for src, although you could also start one like this. However, this would automatically finish the current animation, so you would need to keep track of the old state in order to return to it.
Maybe what I am asking is not the correct thing I should be asking. I did animate(src). animate(src,null). animate(null). Spam clicking still does not reset the object's animation. By spamming it, it seems to just get slower and slower until it no longer animates anymore.

                Click()
var/mob/attackable/player/p = usr
if(istype(p, /mob/attackable/player/))
if(src.icon_state == "Expand Button Up")
src.icon_state = "Expand Button Down"
if(p.extrasObj)
p.client.screen -= p.extrasObj
if(p.closersObj)
p.client.screen -= p.closersObj
animate(p.extrasObj, time = 0)
animate(p.closersObj, time = 0)
else
src.icon_state = "Expand Button Up"

if(!p.extrasObj)
p.extrasObj = new/obj/ScreenObjects/UI/Extras
p.extrasObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.extrasObj

if(!p.closersObj)
p.closersObj = new/obj/ScreenObjects/UI/Closer
p.closersObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.closersObj

var/matrix/m = new()
m.Translate(((32*world.view)*2+1)/2,0)
//m.Scale(1,0)
p.extrasObj.transform = m
p.closersObj.transform = m
animate(p.extrasObj, transform = null, time = 15,easing=ELASTIC_EASING)
animate(p.closersObj, transform = null, time = 15,easing=ELASTIC_EASING)
Clearing the animation and starting a new one at the same time seems not to work. Adding a sleep in between will fix this.

animate(p.extrasObj)
sleep(1)
animate(p.extrasObj, transform = null, time = 15,easing=ELASTIC_EASING)


You won't need to add and delete if you do this.
Adding sleep() didn't do the trick.
What did you do? I just checked this and it worked fine for me.

This is an admittedly mutilated version of your code, but it restarts for me as fast as I can press the verb.
    test3()
var/mob/p = usr

if(!p.extrasObj)
p.extrasObj = new/obj/ScreenObjects/UI/Extras
p.extrasObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.extrasObj
bu = p.extrasObj.transform
var/matrix/m = new()
m.Translate(((32*world.view)*2+1)/2,0)
p.extrasObj.transform = m
animate(p.extrasObj)
sleep(1)
animate(p.extrasObj, transform = null, time = 40,easing=ELASTIC_EASING)
While animate, animates things it also changes the current state of your animated object, at the end of the animation your object's variables were changed, to go back to the beginning you have to change back variables.

For example, if in animate you moved your object via pixel_x/y you can change it back to normal via pixel_x = 0

If you want to kill an animation while it occurs, it doesn't change the fact the change you desired happened as soon as animate() was called, since you only seem to change transform, this should do the trick:
animate(p.extrasObj, transform = null)
animate(p.closersObj, transform = null)
In response to Rotem12
Rotem12 wrote:
While animate, animates things it also changes the current state of your animated object, at the end of the animation your object's variables were changed, to go back to the beginning you have to change back variables.

For example, if in animate you moved your object via pixel_x/y you can change it back to normal via pixel_x = 0

If you want to kill an animation while it occurs, it doesn't change the fact the change you desired happened as soon as animate() was called, since you only seem to change transform, this should do the trick:
> animate(p.extrasObj, transform = null)
> animate(p.closersObj, transform = null)
>


I've already tried that. I'll try it again after breakfast. However, could you investigate one thing for me? It may be a bug... I saw it before I made this post and I think that when you animate something and then remove it from client screen, it bugs things up. Causing the animation to continue and slowly die out but never stop until you wait.

I'm removing it from the screen so they can show and hide the window. But, when they show the window, it slides in. While it works when they wait a second or two, today's society doesn't like to wait with their 3.0GHz+ processors and high GPUs. So, I'm trying to make it appeal to those who get some odd kick out of spamming cool animations.

Edit:

Here it is in it's buggy action!
Best response
Reintroducing the addition and removal of the object from the screen made my example do what your gif does. However, this could be overcome by putting the animate(p.extrasObj) before removing the object from the screen.

Examples:
var/mob/p = usr
if(src.t == 1)
src.t = 0

if(p.extrasObj)
p.client.screen -= p.extrasObj
//if(p.closersObj)
// p.client.screen -= p.closersObj
animate(p.extrasObj)
//animate(p.closersObj, time = 0)
else
src.t = 1

if(!p.extrasObj)
p.extrasObj = new/obj/ScreenObjects/UI/Extras
p.extrasObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.extrasObj
bu = p.extrasObj.transform
/*
if(!p.closersObj)
p.closersObj = new/obj/ScreenObjects/UI/Closer
p.closersObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.closersObj
*/

var/matrix/m = new()
m.Translate(((32*world.view)*2+1)/2,0)
//m.Scale(1,0)
p.extrasObj.transform = m
//p.closersObj.transform = m
animate(p.extrasObj)
sleep(1)
animate(p.extrasObj, transform = null, time = 40,easing=ELASTIC_EASING)
//animate(p.closersObj, transform = null, time = 15,easing=ELASTIC_EASING)


You'll notice that this does the same thing that yours does. However, I made the following change:
var/mob/p = usr
if(src.t == 1)
src.t = 0

animate(p.extrasObj)
if(p.extrasObj)
p.client.screen -= p.extrasObj
//if(p.closersObj)
// p.client.screen -= p.closersObj
//animate(p.closersObj, time = 0)
else
src.t = 1

if(!p.extrasObj)
p.extrasObj = new/obj/ScreenObjects/UI/Extras
p.extrasObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.extrasObj
bu = p.extrasObj.transform
/*
if(!p.closersObj)
p.closersObj = new/obj/ScreenObjects/UI/Closer
p.closersObj.screen_loc = "CENTER-2:8, SOUTH+2:16"
p.client.screen += p.closersObj
*/

var/matrix/m = new()
m.Translate(((32*world.view)*2+1)/2,0)
//m.Scale(1,0)
p.extrasObj.transform = m
//p.closersObj.transform = m
animate(p.extrasObj)
sleep(1)
animate(p.extrasObj, transform = null, time = 40,easing=ELASTIC_EASING)
//animate(p.closersObj, transform = null, time = 15,easing=ELASTIC_EASING)


I believe that this action is what you intended. I'm not certain if it is a bug that you cannot animate while an object is not part of the screen.
In response to Mightymo
Mightymo wrote:
However, this could be overcome by putting the animate(p.extrasObj) before removing the object from the screen.

This whole time I can't believe I didn't realize I was animating it after removing it from the screen. Kill me. I thought I was resetting the animate() before removing it from the screen. Forgive me as I was writing this up after programming nearly 24 hours straight. This solves the issue. Thank you.