iTween: how to ignore the delay in a loop

I want to play a looping scale animation after 5 seconds. But if I set a delay of 5 seconds in my ScaleBy parameters, and set the looptype to pingpong, it seems that the delay is taken into account in every cycle of the loop. That is, 5 seconds will elapse, then my game object will grow for X seconds, then 5 more seconds will elapse, then my game object will shrink for X seconds, repeat…

What I want is a one-time initial delay of 5 seconds, and then a bunch of quick grow/shrink loops. Is there an easy way to accomplish this using a single call with appropriate Hashtable parameters?

1 Answer

1

You could use a coroutine.

Wherever you want to have your animation start after a 5 second delay, put:

StartCoroutine("doAnimation");

Then somewhere else, define the coroutine:

private IEnumerator doAnimation()
{
	yield return new WaitForSeconds(5.0f);

    Hashtable scaleOptions = new Hashtable();
    scaleOptions.Add("loopType", iTween.LoopType.pingPong);
    iTween.ScaleBy(gameObject, scaleOptions);
}

(This was written in C#, check the docs for the JS equivalent if you’re using that.)