Jump to content

Scaling a whole group


Choeeey
 Share

Recommended Posts

Hi there,

 

Basically I have a group: 

 

 this.walls = game.add.group();

 

And I add a LOT of walls, but each time I do I need to scale them like so:

 

 this.wall1 = this.add.sprite(positionx,positiony, 'wall', 0, this.walls);
                    this.wall2 = this.add.sprite(x,y, 'wall', 0, this.walls);
                    this.wall3 = this.add.sprite(x,y, 'wall', 0, this.walls);
                    this.wall4 = this.add.sprite(x,y, 'wall', 0, this.walls);
                         
                    this.wall1.width = this.wall1.width*scale;
                    this.wall1.height = this.wall1.height*scale;
                    this.wall2.width = this.wall2.width*scale;
                    this.wall2.height = this.wall2.height*scale;
                    this.wall3.width = this.wall3.width*scale;
                    this.wall3.height = this.wall3.height*scale;
                    this.wall4.width = this.wall4.width*scale;
                    this.wall4.height = this.wall4.height*scale;
 
Is there a way I can scale the whole group in one?
Link to comment
Share on other sites

You're saying you want to scale each element but not the distances between them? You'll have to resize each one individually, but you can do this with forEachAlive:

create: function(){  this.walls = game.add.group();  //(...)  //add walls to group...  //(...)  this.walls.forEachAlive(this.resizeWall, this);},resizeWall: function(member) {  member.scale.set(scale)}

This will cycle through all the elements of the group and resize them individually. Just remember that they're resized around the anchor point, so you might want to change that.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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