Interpolate & Constrain

Hi guys, another question.
Can somebody explain to me what the 'Constrain Attribute' and 'Interpolate' behaviors actually do. I follow tutorials and copy code which use these behaviors but i'm actually not clear on what they do and how to use them properly in my own code. Any help would be appreciated.
Thanks,
Liamo
Can somebody explain to me what the 'Constrain Attribute' and 'Interpolate' behaviors actually do. I follow tutorials and copy code which use these behaviors but i'm actually not clear on what they do and how to use them properly in my own code. Any help would be appreciated.
Thanks,
Liamo
Comments
Interpolate is away of gliding between 2 values. A start value and some other value. example- Interpolate self position of actor X to 240. This would change the actor's x position to 240 and if you look at the interpolate there is a field to enter over what time to make that change and option to ease in or out or both so it would smoothly arrive, depart, or booth, so it is not a harsh in the way if arrives etc.
hope that helps kipper
That being said, interpolate is great because there are so many attributes out there that use number values. You can interpolate the alpha of an actor from 0 to 1 and have a fade in effect. Or if you reverse those numbers and interpolate the alpha of an actor from 1 to 0, the you would have a fade out effect.
This can be used in conjunction with rules. For example:
1) Rule:
When actor overlaps or collides with actor of type "bomb"
...interpolate self.alpha to 0 for 0.4 seconds - linear
2) Rule:
When self.aplha = 0
...destroy
In this instance it's effective because it removes the need to have a timer (which are performance hogs).
The example of creating the same effect with the use of a timer is as follows:
Rule:
When actor overlaps or collides with actor of type "bomb
...interpolate self.alpha to 0 for 0.4 seconds - linear
...timer
.....after 0.4 seconds
........destroy
Interpolates cannot be interrupted, so if you have an interpolate that says change the alpha from 1 to 0 for 10 seconds, a change attribute won't stop the interpolation for those 10 seconds. Interpolate is good because it allows you to move from specific x,y points without needing to have the actor be "moveable". This helps out with performance in the long run.
Also, interpolating actors DO NOT COLLIDE. So you wouldn't interpolate a bullet actor because it would never hit its target.
*Pro Tip:
You can use a constrain to "stop" an interpolate. You aren't actually stopping the interpolate, but the user won't know that. Say you are interpolating an actor's alpha from 0 to 1 for 10 seconds. Well, you could create another rule inside that actor that says
Rule:
if "so and so happens"
...constrain self.alpha to .5(or whatever number you choose between 0 and 1)
Constrains hold precedence over interpolates.
Constrains are also performance hogs, but if used sparingly and for a limited amount of time, you'll be all right.