ITween OnComplete Queuing Activity Requests

I’m new to unity and found itween to be handy for small animations to trigger. So I have a bumper (collider) that when hit by a rigidbody runs a function that rotates a pinwheel ( disk split into 5 equal parts 72• , a pie like shape) the animation of this disk rotating takes 0.5 seconds. But sometimes the function get resent while it currently rotating and interferes my active tween and stops it.
I was thinking of setting up a boolean value isTweening from true to false to the itween functions callback but i just cant get it to trigger of my other function. The callback example provided on the itween website is showing a function that runs itself, looping and I’m having a problem figuring it out. Can you ask I tween to check if something is tweening? Can I build a cue of events in an array and make an update to run through them?

I have a counter setup that counts the number if rotate functions requested

it’s the mostly the overlapped events I can’t understand. How would you handle it?

to explain my self in code…

public var count : int =0;
public var IsSpinning: Boolean = false;

function RotateDisk(){
if (!IsSpinning){
IsSpinning = true;
var _Colordisk = GameObject.FindWithTag ("Colordisk");
count+=1;
iTween.rotateBy(Colordisk ,{"x":0,"y":0.2,"z":0, "time":0.5,"transition":"easeInOutQuint","isLocal":true,"onComplete":"CallbackThingy"});
}else{
//see if any events overlapped?
}
}


function CallbackThingy(){
IsSpinning = false;
//see if any events overlapped?
//wait for it to finish?
}

* just an example / not actual

the itween example code that the callback kinda runs itself is

private var tweenTarget : GameObject;
var counter : GUIText;
var count : int =0;

function Start(){
	tweenTarget=gameObject;
	roll("right");
	counter.guiText.material.color = Color.black;
}

private function roll(direction: String): void{
	switch(direction){
		case "right":
		iTween.rotateBy(tweenTarget,{"z":-.5});
		iTween.moveTo(tweenTarget,{"x":1.7, "onComplete":"roll", "onCompleteParams":"left"});
		count+=1;
		break;
		
		case "left":
		iTween.rotateBy(tweenTarget,{"z":1});
		iTween.moveTo(tweenTarget,{"x":-1.7, "onComplete":"roll", "onCompleteParams":"right"});
		count+=1;
		break;
	}
	
	counter.text=count.ToString() + " Loops";
}

Hope this sheds a little light on the inner workings of iTween. Anytime a new iTween is added to a GameObject and it is of the same type (i.e. if a moveTo is running and any other type of moveTo, moveBy, moveAdd is set to start while the previous is in progress) iTween will destroy the running tween and replace it with the new one.

Does this help you out some?

thanks for you reply
i considered someone would help out, without me bugging you but here you are 8)

i think i understand what you mean.

you had a couple of issues with my approach.

a. i was trying to run a different function on the “onComplete”, is that possible?

b. a friend suggested a have a look at maybe inProgress or tweenCount(gameObject). do you have a snippet that could explain me it’s usages?

what im trying to achive is some type of event queue of tweens of sorts

i saw this in your code while googing around…

//Tween count retrieval:
static function tweenCount(obj: GameObject) : int{
	var scripts = obj.GetComponents (iTween);
	return scripts.Length;
}

so , to see/use that… is it?

print(GameObject.tweenCount())

or maybe?

if (GameObject.tweenCount()==1)
{
//do this
}else{
// do plan b
}

if you use yield you can achieve a que

ie.

iTween.move;
yield;
Itween.dance;
yield;
ect.

I made iTween to help people out so why stop now :wink:

What exactly do you mean by running a different function on the “onComplete”?

I wouldn’t rely on tweenCount very much for what you are attempting as I didn’t flesh it out very much in 1.0. However in 2.0, in addition to a whole slew of new tools (pause, resume, stop, rewind, complete) there are 4 new count methods that allow you to:
-Count all iTweens in GameObject
-Count all iTweens in GameObject of type
-Count all iTweens in scene
-Count all iTweens in scene of type

You could look into the “registers” array to see what all iTweens you have running (this is known as just “tweens” in 2.0).

Hope this at least gets you running down some direction.

P.S. you can watch the development of 2.0 at Google Code Archive - Long-term storage for Google Code Project Hosting.

Good luck! Gotta get back to work :wink:

P.S. To use tweenCount:

print(iTween.tweenCount(gameObject));

Just as a heads up, this approach wouldn’t work with iTween since it attaches self running scripts that wouldn’t have anything to do with the calling scripts. The ticket to stacking iTweens is in using it’s delay property.

orly??? thats interesting - i stand corrected

:smile:
Take a look at the “Hello World - Complex” example from the support site: http://itween.pixelplacement.com/

yeah it makes sense now that i think about it - i just never stacked ITween scripts like that so i never ran into this issue

If you didn’t care that every iTween would run for the same amount of time (1 second long) you could do something like this (or change the default time value in iTween’s defaults):

function Start() {
   var go : GameObject = gameObject;
   var delay : int = 0;
   iTween.rotateBy(go,{"x":.3,"delay":delay++});
   iTween.rotateBy(go,{"x":-.3,"delay":delay++});
   iTween.rotateAdd(go,{"x":30,"delay":delay++});
   iTween.rotateAdd(go,{"x":-30,"delay":delay++});
   iTween.moveTo(go,{"x":1,"delay":delay++});
   iTween.moveTo(go,{"x":0,"delay":delay++});
   iTween.moveAdd(go,{"x":2,"delay":delay++});
   iTween.moveAdd(go,{"x":-2,"delay":delay++});
}

sorry for delay, thanks for all the tips advice.
will give this all a go :slight_smile: