Jump to content

Player collide with floor sides?


anthkris
 Share

Recommended Posts

Howdy all,

I've looked everywhere but I can't seem to find an answer. I'm making an infinite scroller. The platforms are automatically generated and they are made up of a pool of floor sprites nested into a pool of platforms (groups of floor sprites). For example:

// Creating platforms in Game.js

createPlatform: function(){
    var nextPlatformData = this.generateRandomPlatform();
    
     if (nextPlatformData) {
       this.currentPlatform = this.platformPool.getFirstDead();
       if (!this.currentPlatform) {
         this.currentPlatform = new SupRun.Platform(
this.game, this.floorPool, nextPlatformData.numTiles,this.game.world.width + nextPlatformData.separation, 
nextPlatformData.y, -this.levelSpeed, this.coinsPool, this.enemiesPool, this.enemySprite, 
this.player, false);
       } else {
         this.currentPlatform.prepare(
nextPlatformData.numTiles, this.game.world.width + nextPlatformData.separation, 
nextPlatformData.y, -this.levelSpeed, this.coinsPool, this.enemiesPool, this.enemySprite, 
this.player, false);
       }
       
       this.platformPool.add(this.currentPlatform);
       this.currIndex++;
     }
  }

//Creating groups of floor sprites in Platform.js prefab

SupRun.Platform.prototype.prepare = function(numTiles, x, y, speed, player) {
  //console.log(speed);
  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);
    
    i++;
  }
  //set physics properties
  this.setAll('body.immovable', true);
  this.setAll('body.allowGravity', false);
  this.setAll('body.velocity.x', speed);
  
  this.addCoins(speed);
  this.addEnemies(speed, this.player);
  
};

 

The player collides with the top of the of the platforms just fine. However, I would like the player to hit the side of the wall and just fall straight down, instead of falling through.

Screen Shot 2017-01-23 at 12.16.35 AM.png

Is this possible?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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