Even when changing the X position restarting tween makes it go back to the original one

#1

i dont understand why, is the start and end position saved in the tween so if i restart it, it will take the results from there? If so, how do i edit these values?

#2

You might need to post your tween code, so it’s a bit easier to understand your question. But I imagine you’re setting a fixed value in the tween (for example x: 50). As an alternative, you could set an assignment string (x: ‘+=50’). You can also update a playing tween with updateTo.

#3

Thank you for your reply!

My problem is not the ending X, but the repositioning of the X.

    this.children.entries.forEach(function(element) {
      element.scene.clouds.cloudTweens.push(element.scene.tweens.add({
            targets: element,
            x: { value: Math.random() * (700 - 450) + 450},  
            duration: Math.random() * (15000 - 10000) + 10000, 10000
            ease: 'linear',
            repeat: -1
        }));
    });
}   

then what i do when i need it is, set a new X and Y position and restart the tween, the Y works fine, but the X is always the X which it started as (the one i declared when creating the sprite), this class extend s a arcade.staticgroup, but ive also tried with group and the results seem to be the same

#4

Hi @LifeEternal ,
This should work:

this.children.entries.forEach(function(element) {
      element.scene.clouds.cloudTweens.push(element.scene.tweens.add({
            targets: element,
            x: function() { 
                return Math.random() * (700 - 450) + 450; 
                 },  
            duration: function(){
                return Math.random() * (15000 - 10000) + 10000;
                 },
            ease: 'linear',
            repeat: -1
        }));
    });

Regards.

#5

my problem is with the starting X position, i wanna change that, i already have the tween proprety ‘x’ set to +=50

#6

Ups ok,
Try this:

this.children.entries.forEach(function(element) {
      element.scene.clouds.cloudTweens.push(element.scene.tweens.add({
            targets: element,
            x: {
              value: {
                getStart: function(target, key, value){
                  return value + 50;
                },
                getEnd: function(){
                  return Math.random() * (700 - 450) + 450;
                }
              }
            },  
            duration: function(){
                return Math.random() * (15000 - 10000) + 10000;
                 },
            ease: 'linear',
            repeat: -1
        }));
    });

Regards.