Jump to content

Using scale and alpha in one tween


shmikucis
 Share

Recommended Posts

Is there an easy way to use scale and alpha in one tween?

 

I know that you can combine position and alpha like this

game.add.tween(sprite).to({x: 100, alpha: 1},...)

But regarding to scaling there needs to be sprite.scale parameter added instead of just sprite . And this makes things more complicated.
 

game.add.tween(sprite.scale).to({x: 2, y:2},...)
Link to comment
Share on other sites

  • 8 months later...

Like this?

game.add.tween(sprite).to({x: 100});game.add.tween(sprite.scale).to({x: 2, y: 2});

As long as the properties are different the 2nd tween won't replace the first one.

 

And what if I need that as a single variable so I can chain the tween with another one? Struggling for a lot of hours to make something rather simple... :(

 

var ratio = 200;var delay = 800;var moves = 7;var moveRight = this.add.tween(this.snake).to( { x: '+100' }, ratio, null, false, delay, moves);moveRight = this.add.tween(this.snake.scale).to( { x: 1 }, 100);var moveLeft = this.add.tween(this.snake).to( { x: '-100' }, ratio, null, false, delay, moves);moveLeft = this.add.tween(this.snake.scale).to( { x: -1 });moveRight.chain(moveLeft).start();
Link to comment
Share on other sites

  • 1 year later...
this.player = {  x: 1, y: 1, alpha: 1 }; 
this.tweenEffect = game.add.tween(this.player).to( { x: 2, y: 2, alpha: 0 }, 2000, Phaser.Easing.Linear.None, false, 0, 0, false);
tweenEffect.onComplete.add(onComplete, this);

Is this the way to add scale and alpha as custom properties?

It doesn't work for me. 

I also need to call onComplete after both scale and alpha values are changed.

Link to comment
Share on other sites

On 3/7/2014 at 8:52 AM, rich said:

Like this?


game.add.tween(sprite).to({x: 100});game.add.tween(sprite.scale).to({x: 2, y: 2});

As long as the properties are different the 2nd tween won't replace the first one.

I think there would a lot of benefits, for the sake of code brevity, to be allowed to do this sort of action in one tween. This examples uses 2 tweens. It's not a big deal - but perhaps something to think about in Phaser 3 :). 

Link to comment
Share on other sites

Ah, I see. If the 2nd tween won't replace the first one, a workaround would be to assign a variable to the second tween and use it to check onComplete.

game.add.tween(this.child.scale).to( { x: 2, y: 2 }, 1000, Phaser.Easing.Linear.None, true, 0, 0, false);
var myTween = game.add.tween(this.child).to( { alpha: 0 }, 1000, Phaser.Easing.Linear.None, true, 0, 0, false);

mytween.onComplete.add(function() {
      //reset size and transparency  
      this.child.scale.setTo(0);
      this.child.alpha = 1;

    }, this);

 };

 

Link to comment
Share on other sites

  • 1 year later...

You can use only one tween - just use width/height in tween instead scale tweening
 

game.add.tween(this.child).to( { width: this.child.width*2, height: this.child.height*2, alpha: 0 }, 1000, Phaser.Easing.Linear.None, true, 0, 0, false);

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...