Jump to content

Create multiple groups - 'for' loop?


3man7
 Share

Recommended Posts

Hey guys,
I have a quick question about 'Groups' as I'm kinda new to this Phaser HTML5 game dev.

So my plan is to create multiple groups and have control over each one of them. First thing that came into my mind is to create a 'for loop' and be done with! Problem is that I don't know how to assign different names for a variable (wave).Example:
Instead of doing this:

this.wave00 = game.add.group();
this.wave00.enableBody = true;
this.wave00.physicsBodyType = Phaser.Physics.ARCADE;

this.wave01 = game.add.group();
this.wave01.enableBody = true;
this.wave01.physicsBodyType = Phaser.Physics.ARCADE;

this.wave02 = game.add.group();
this.wave02.enableBody = true;
this.wave02.physicsBodyType = Phaser.Physics.ARCADE;

I am trying to do this:

for(i=0; i<10; i++){
    this.['wave'+i] = game.add.group();
    this.['wave'+i].enableBody = true;
    this.['wave'+i].physicsBodyType = Phaser.Physics.ARCADE;
}

So I'm sure you got the idea but this (['wave'+i]) is the problem.

Can someone help me with this? What is the correct way of writing it? I've been searching but maybe I'm not questioning this correctly.

Thanks and sorry for the noob question!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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