Interpolate & Constrain

liamoliamo Member Posts: 191
edited November -1 in Working with GS (Mac)
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

Comments

  • old_kipperold_kipper Member Posts: 1,420
    Constrain is like a lock or pinning to something. You can use it fix one thing to another. like 'constrain' actor a's X position to the X position of actor b's X, or contrain actor C's X and Y to touch one's X and Y.

    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
  • entersimonentersimon Member, PRO Posts: 273
    It's also important to know that interpolate is used to change attributes that have a number value associated with them. This may seem obvious to some, but it helps clear up the nature of the behavior.

    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.
Sign In or Register to comment.