shmikucis Posted March 7, 2014 Share Posted March 7, 2014 Is there an easy way to use scale and alpha in one tween? I know that you can combine position and alpha like thisgame.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 More sharing options...
rich Posted March 7, 2014 Share Posted March 7, 2014 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. Pooya72 1 Link to comment Share on other sites More sharing options...
BunBunBun Posted March 7, 2014 Share Posted March 7, 2014 game.add.tween(sprite).to({alpha: 0}); game.add.tween(sprite.scale).to({x: 2, y: 2}); Link to comment Share on other sites More sharing options...
shmikucis Posted March 7, 2014 Author Share Posted March 7, 2014 That does work, thanks! Link to comment Share on other sites More sharing options...
Dread Knight Posted December 1, 2014 Share Posted December 1, 2014 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 More sharing options...
jouniii Posted December 5, 2014 Share Posted December 5, 2014 Use object properties. Define a new property and tween that. The defined property then may do whatever you want. I've used that a lot for more complex tweens. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty Link to comment Share on other sites More sharing options...
piotr Posted October 7, 2016 Share Posted October 7, 2016 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 More sharing options...
ForgeableSum Posted October 7, 2016 Share Posted October 7, 2016 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 More sharing options...
piotr Posted October 8, 2016 Share Posted October 8, 2016 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 More sharing options...
Zaxx Posted August 31, 2018 Share Posted August 31, 2018 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 More sharing options...
Recommended Posts