Jump to content

Adding tweens to groups


roscminni
 Share

Recommended Posts

Hi,

 

I'm just starting out with Phaser, really like it so far and have managed to figure most things out from the examples and this forum.

 

I was wondering if there was any way to add a tween to a group? I am guessing you might use the forAll function, but I'm not sure how this works.

 

This is what I would like to do:

game.add.tween(titleScreen).to({alpha: 0},2000,Phaser.Easing.Linear.None,true);

Where titleScreen is a group of sprites that comprise my title screen.

 

Thanks,

 

Anton

 

Link to comment
Share on other sites

By using an array I was able to fade out my title screen like so:

var titleScreen = [elements];for(var i =0; i < titleScreen.length; i++){      game.add.tween(titleScreen[i]).to({alpha: 0},1000,Phaser.Easing.Linear.None,true);};					

This is perhaps the best way to achieve what I need, however I would still like to know what is possible with the group object.

Link to comment
Share on other sites

Hi, yes it's possible to tween a group object's alpha, but unfortunately, the alpha property is not exposed directly so you will have to do it like this:

game.add.tween(titleScreen._container).to({alpha: 0},2000,Phaser.Easing.Linear.None,true);
Link to comment
Share on other sites

Group.alpha is a public property now (as of this morning!) which works if you want to fade a group out/in. But if you want to apply a tween to every child of the group there's no direct way at the moment, so you'd need to use one of the Group iteration methods (forEach perhaps) and apply them that way.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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