Jump to content

Groups Collision


pete796
 Share

Recommended Posts

Hello, 

I'm following an online tutorial and had a question regarding the code shown below.

I was wondering what this.add(floorTile) does?   I assume this is adding the floor tile sprites to a group?

Note, I have removed much of the code for brevity. 

 



    this.floorPool = this.add.group();
    this.platformPool = this.add.group();
 
    this.platform = new MrHop.Platform(this.game, this.floorPool, 12, 0, 200);
    this.platformPool.add(this.platform);



MrHop.Platform.prototype.prepare = function(numTiles, x, y) {
  this.alive = true; 
    
  var i = 0;
  while(i < numTiles){  
    var floorTile = this.floorPool.getFirstExists(false);
    
    if(!floorTile) {
      floorTile = new Phaser.Sprite(this.game, x + i * this.tileSize, y, 'floor');
    }
    else {
      floorTile.reset(x + i * this.tileSize, y);
    }
      
    this.add(floorTile);
  }
}


  update: function() {    
    this.platformPool.forEachAlive(function(platform, index){
      this.game.physics.arcade.collide(this.player, platform);
    }, this);
  },

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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