# How to Update Tween Properties?

**URL:** <https://phaser.discourse.group/t/how-to-update-tween-properties/5198>\
**Category:** Phaser 3\
**Created:** [February 15, 2020, 8:36am UTC](https://phaser.discourse.group/t/how-to-update-tween-properties/5198 "2020-02-15T08:36:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FKL34TI5T5](https://avatars.discourse-cdn.com/v4/letter/f/df788c/32.png) [@FKL34TI5T5](https://phaser.discourse.group/u/FKL34TI5T5)\
**Post date:** [February 15, 2020, 8:36am UTC](https://phaser.discourse.group/t/how-to-update-tween-properties/5198/1 "2020-02-15T08:36:39Z")

</div>

I want to change the duration randomly just before I play a tween. How can I update a specific tween’s properties?

```
var tween = this.tweens.create({ targets: sprite, x: 50, y: 50, duration: getDuration(100,500), ease: 'Back', easeParams: [.5], repeat: 0 })

function playTween() {
tween.updateTo('duration', getDuration(100,500)) //<= This doesn't work.
tween.play()
}

function getDuration(min, max) {
    return Math.floor(Math.random() * (max - min)) + min
}
```

---

<div class="post-metadata">

**Author:** ![Telinc1](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/telinc1/32/60_2.png) [@Telinc1](https://phaser.discourse.group/u/Telinc1)\
**Post date:** [February 15, 2020, 4:17pm UTC](https://phaser.discourse.group/t/how-to-update-tween-properties/5198/2 "2020-02-15T16:17:38Z")

</div>

The `duration` of a tween can be a function (instead of a number) which will be called every time the tween is initialized. Try using `duration: getDuration.bind(null, 100, 500)` in the tween config ([`bind` creates a function with pre-filled arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)).

`updateTo` affects the properties of the object affected by the tween, not the tween itself.

---

<div class="post-metadata">

**Author:** ![FKL34TI5T5](https://avatars.discourse-cdn.com/v4/letter/f/df788c/32.png) [@FKL34TI5T5](https://phaser.discourse.group/u/FKL34TI5T5)\
**Post date:** [February 15, 2020, 5:44pm UTC](https://phaser.discourse.group/t/how-to-update-tween-properties/5198/3 "2020-02-15T17:44:11Z")

</div>

Perfect, something I did not consider.

What does the null argument do? Is that a callback?

---

<div class="post-metadata">

**Author:** ![Telinc1](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/telinc1/32/60_2.png) [@Telinc1](https://phaser.discourse.group/u/Telinc1)\
**Post date:** [February 15, 2020, 6:00pm UTC](https://phaser.discourse.group/t/how-to-update-tween-properties/5198/4 "2020-02-15T18:00:28Z")

</div>

> [@FKL34TI5T5](#):
>
> What does the null argument do? Is that a callback?

The one to `bind`? It’s the value that `this` will have inside the function. I’ve left it as `null` because it’s not used in `getDuration`.
