[SOLVED] Tween fail

Hi - I’m unable to do the simplest tween and I don’t know why - here’s the example

    this.num = 0;

    this.app
    .tween(self.num)
    .to(100, 1.0, pc.Linear)
    .on('update', function () {

        console.log("this num="+self.num);

    }).start();

Why won’t this count up to 100 ? It just stays on 0. What am i missing folks ?

Hi @jerryComo,

The Tween library relies on object properties in order to manipulate values, so it can’t tween a number directly. You can fix this by wrapping your numbers in a an object like this:

this.num = {value: 0};

    this.app
    .tween(self.num)
    .to({value: 100}, 1.0, pc.Linear)
    .on('update', function () {

        console.log("this num="+self.num.value);

    }).start();

For more information about Tweening, feel free to check out the Git repository documentation here:

I hope this is helpful.

Edit to add that the value you are editing will also need to be wrapped in an object. I have edited my code above. Sorry about that!

2 Likes

thanks for that - When I past that into my method it still remains on zero though.

Yep! Sorry about that. I edited my post above before you replied. The value will also need to be wrapped in an object. See the edited post above.