x


iTween ValueTo onUpdateParams passing

I'm trying to make 4 HP bar to drop down smoothly using iTween The HP bar is a 64-pixel-wide GUITexture

var hpBar : GUITexture[];

function Tween()
{
    iTween.ValueTo (gameObject, iTween.Hash("from"     , hpBar[0].pixelInset.width,
                                     "to"   , chara0curHP/chara0totalHP*64,
                                     "time"       , 0.5,
                                     "onUpdate"    , "HPBar0Tween")
                 );
    iTween.ValueTo (gameObject, iTween.Hash("from"     , hpBar[1].pixelInset.width,
                                     "to"   , chara1curHP/chara1totalHP*64,
                                     "time"       , 0.5,
                                     "onUpdate"    , "HPBar0Tween")
                 );
    iTween.ValueTo (gameObject, iTween.Hash("from"     , hpBar[2].pixelInset.width,
                                     "to"   , chara2curHP/chara2totalHP*64,
                                     "time"       , 0.5,
                                     "onUpdate"    , "HPBar0Tween")
                 );
    iTween.ValueTo (gameObject, iTween.Hash("from"     , hpBar[3].pixelInset.width,
                                     "to"   , chara3curHP/chara3totalHP*64,
                                     "time"       , 0.5,
                                     "onUpdate"    , "HPBar0Tween")
                 );
}

function HPBar0Tween(val : int) { hpBar[0].pixelInset.width = val;}
function HPBar1Tween(val : int) { hpBar[1].pixelInset.width = val;}
function HPBar2Tween(val : int) { hpBar[2].pixelInset.width = val;}
function HPBar3Tween(val : int) { hpBar[3].pixelInset.width = val;}

My question is, how can I cut down the number of onUpdate functions by providing the 2nd parameter to onUpdateParams function? I've tried to supply Hashtable as argument for onUpdateFunction and iTween doesn't accept it. I've already tried to supply JavaScript Object as the argument and iTween treat them as int

What would be my other options rather than this long,messy, unelegant way of handling it?

I appreciate any feedback

more ▼

asked Nov 08 '11 at 09:05 AM

Solitude01 gravatar image

Solitude01
61 8 11 12

I have the same question

May 05 '12 at 03:46 AM fanling3
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

With the solution prevented by karsten here, you only need to change 3 lines of code in iTween, and can then use an inline delegate for "onupdate"/"oncomplete"/"onstart" (instead of an explicit function) to execute arbitrary code with any parameters you like.

So for example you could then do something like:

        string colorToChange="_Color";
        iTween.ValueTo(gameObject, iTween.Hash(
            "from", a,
            "to", b,
            "onupdate", (Action<object>) (newVal => {
                Debug.Log("running iTween onupdate for "+colorToChange+" "+(float)newVal);
                renderer.material.SetColor(colorToChange,Color.white*(float)newVal);
            }
        ));

NOTE: I don't know whether this works in US/JS, too, or whether the syntax would change.

more ▼

answered Jul 05 '12 at 01:06 PM

Wolfram gravatar image

Wolfram
9.1k 8 20 53

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3570
x435
x7
x2

asked: Nov 08 '11 at 09:05 AM

Seen: 1808 times

Last Updated: Jul 05 '12 at 01:06 PM