ID:2062941
 
(See the best response by Ter13.)
Hey guys,
I have 2 questions in regards to animate. If anyone can provide insight or some code in order to help me with what I'm working on, that would be much appreciated!!

1. How can I loop two animates, one after the other? Example: A light that animates from 0 alpha to 255 and than back from 255 to 0.

2. How can I loop a matrix scale transformation. As in, making something go from a matrix of 3 to 6 and than back from 6 to 3.

animate(src,alpha=0,loop=-1,time=10)


The 'loop' argument in animate() can loop the animation, -1 is forever, any other number will loop it that many times before stopping.
Thanks Nadrew, but that's not what I'm looking for.

If an object had an alpha of 255 and I used
animate(src,alpha=0,loop=-1,time=10)
- The object would go from 0 to 255 and than instantly back to 0.

I want something to animate from 0 to 255 than just as smoothly back to 0 to animate once again to 255.
Best response
animate() works with multiple steps. The first time you call animate() you specify the object.

If you call animate again without specifying the object, it adds on to the existing animation. A single step animation will animate from 255 to 0 and then instantly reset to its initial values, then animate from 255 to zero again.

To smoothly go back and forward, you will want to create a two-step animation. This is simple:

animate(src,alpha=0,time=10,loop=-1)
animate(alpha=255,time=10)


This creates a two-step animation that loops indefinitely where each step takes 10 ticks and the whole loop takes 20 ticks.

Your second question:

var/matrix/m1 = transform
var/matrix/m2 = transform
m1.Scale(3,3)
m2.Scale(6,6)
transform = m1
animate(src,transform=m2,time=10,loop=-1)
animate(transform=m1,time=10)
Thanks a lot guys, I appreciate the help! =)