Jump to content

Move all object of the group


bru
 Share

Recommended Posts

Hello, i have a group of platforms :

create: function {this.platforms = this.game.add.group();this.platform = this.platforms.create(thsi.game.with, this.game.height-100, 'yellow');        this.platform.anchor.setTo(0, 1);        this.platform.scale.setTo(10, 1);        game.physics.enable(this.platform, Phaser.Physics.ARCADE);        this.platform.body.immovable = true;        this.platform.body.reset(startwidth, startheight);}

and i make them move like this :

update: function{      this.platform.body.x -= 10;}

The problem is, when a new platform come the last one stop moving, instead of move until leave the screen, is there any way to solve this ?

Link to comment
Share on other sites

You are only updating one platform at a time in the update function.

I assume that every time you create a new platform, you assign it to the this.platform variable, which would cause the existing platform to stop moving.

 

You would be better off iterating over the children of the this.platforms group and updating each platform that way.

Look at Group.forEach and Group.ForEachAlive.

update: function{    this.platforms.forEachAlive(function(platform)    {        platform.body.x -= 10;    }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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