ITween not working in update function?

function Update () {
	SetDesiredSize();
	SetDesiredPos();
	ButtonTween();

}
function SetDesiredSize(){
    for(var i:int = 0;i<PauseMenuButtons.Count;i++){
       if(i==PauseMenuPositionStatus){
         desiredSize[i]=SelectedSize;
       }
       else{
         desiredSize[i]=unSelectedSize;
       }

    }
}

function SetDesiredPos(){
    desiredPos[0]=Vector2(Screen.width*.02,Screen.height*(1-.02)-desiredSize[0].y);
    for(var i:int = 0;i<PauseMenuButtons.Count;i++){
       if(i!=0){
         desiredPos[i]=Vector2(Screen.width*.02,desiredPos[i-1].y - desiredSize[i].y);
       }
    }
}

function ButtonTween(){
    iTween.ValueTo(gameObject,iTween.Hash("from",currentPos[0],"to",desiredPos[0],"onupdate","MoveButtonPos","easetype","easeinoutback"));

}
function MoveButtonPos(myVector2:Vector2){
    PauseMenuButtons[0].pixelInset.x=myVector2.x;
    PauseMenuButtons[0].pixelInset.y=myVector2.y;

}

If I put an Itween in update function, it will stuck to its starting position.Anyone who know how to solve this problem please help.

Why are you PMing everyone? It doesn’t offer any help to folks who come to this thread via search results later down the line. I also don’t see the point in posting (twice) in a thread to let someone know that you are sending them a PM.

To the OP - you’re kicking off the tween every single frame which is probably not what you want to do. Why not set it up and start it in Start instead?

hi, i tried it in start. But that’s also not what i want. Because i want it update when the joystic is moved.

iTween gives you the option to declare a method that is executed after the tween is complete. In Update check your joystick input and set a boolean flag (something like isTweening) to true and kick off your iTween. Do not kick off any other iTweens until isTweening is set back to false which is done in the method you declared as the “oncomplete” method.

I think i lost…lol

can you be more specific about “iTween gives you the option to declare a method that is executed after the tween is complete”

thanks…:smile:

http://itween.pixelplacement.com/documentation.php

Every method has an optional argument called “oncomplete”. This is the function that is executed when the tween finishes.

function ButtonTween(){
	if(menuMove  !isTweening){
		iTween.ValueTo(gameObject,iTween.Hash("from",currentSize[0],"to",desiredSize[0],"onupdate","MoveButtonSize0","onstart","IsTweeningOn","oncompelete","isTweeningOff","easetype","easeinoutback","time",animateTime));
		iTween.ValueTo(gameObject,iTween.Hash("from",currentPos[0],"to",desiredPos[0],"onupdate","MoveButtonPos0","easetype","easeinoutback","time",animateTime));

	}
	
}
function MoveButtonPos0(myVector2:Vector2){
		PauseMenuButtons[0].pixelInset.x=myVector2.x;
		PauseMenuButtons[0].pixelInset.y=myVector2.y;
}
function MoveButtonSize0(myVector2:Vector2){
		PauseMenuButtons[0].pixelInset.width=myVector2.x;
		PauseMenuButtons[0].pixelInset.width=myVector2.y;
}

var isTweening:boolean=false;

function isTweeningOn(){
	Debug.Log("works");
	isTweening=true;
}

function isTweeningOff(){
	isTweening=false;
}

I tried something like this…But the “onstart” and “oncompelete” function is not triggered.:face_with_spiral_eyes:

Did I type something wrong?

Ah…anyway…I solved the problem.

I added if(!iTween)…so if iTween haven’t been called, it’ll call it, after it’s called, the script will stop. And the animation wont stuck at the begining position.

For one thing, it’s oncomplete not oncompelete.