ID:2065046
 
I'm trying to get a dart to travel across the screen. When various events happen, I want the dart to stop moving but remain where it was stopped. With the following example code, the dart is disappearing on me when it reaches the half way point when I was expecting it to just stop. How can I halt the animation while leaving the object right where it is?

Code:
var/Dart/d = new(locate(1, 10, 1))

// Send the dart across the screen
animate(d, pixel_x = 500, time = 100, easing = SINE_EASING, EASE_OUT)

spawn()
// When the dart gets half way, end the animation and leave the dart where it is
while(d.x < 250)
sleep(2)
animate(d)



You'll have to compute the final position since animate() sets all values immediately to the final value.
Wouldn't the expected behavior be to halt it right where it's at? Seems like a flag to define the stop behavior would be useful.

Not sure how I would go about computing the current position mid-animate.
In response to PopLava
To the server, calling animate(d, pixel_x = 500, etc.) immediately sets pixel_x to 500. The animation you see is just played on the client. The dart is never actually between its initial and final position, and pixel_x is never a value between its initial value and 500.

Computing the position mid-animate would require knowledge of the easing curve used by it, which I don't have much of.
Animation is basically a client-side phenomenon. If you want a specific end state, you have to plan the animation that way from the beginning. (BTW, you now have access to QUAD_EASING in 510; it might suit your purposes better.)
After playing around with it for a while, I did find that I can achieve the desired effect by overlaying an animation call with a really large time value.

var/Dart/d = new(locate(1, 10, 1))

// Send the dart across the screen
animate(d, pixel_x = 500, time = 100, easing = SINE_EASING, EASE_OUT)

spawn()
// Wait until the dart reaches its target
while(!d.m_HasReachedDestination)
sleep(2)

// Delay animations for so long that they appear stopped. Note, it will move a pixel every so often.
animate(d, time = 500000)


If I want to give the appearance of slowing to halt, I just call animate a number of times with increasing time values.

var/Car/c = new(locate(1, 10, 1))

// Send the car across the screen
animate(c, pixel_x = 500, time = 100, easing = SINE_EASING, EASE_OUT)

spawn()
// Wait until the car reaches its destination
while(!c.m_HasReachedDestination)
sleep(2)

// Appear to slow down before stopping
for (var/i = 1; i < 10; i++)
animate(c, time = i * 500)
sleep(3)

// Appear to stop.
animate(c, time = 500000)