Jump to content

Shouldn't body.blocked.down be true in this case?


Recommended Posts

In a platformer game, when using the Arcade mode, body.blocked.down is true when you are stepping on the world boundary (like in the platformer example) on when on tile ground.


But when standing on another sprite (for example a sprite for the floor with body.immovable = true) it currently shows body.blocked.down as false, but body.touching.down true.


I have a demo for a basic platformer, to implement the jump functionality I want to test for blocked, because if I test for touching.down then the character also jumps when touching non-blocking elements (that overlap not colllide).


So my question is, is this the expected behavior for body.blocked? how could I just test just for blocking objects to implement jump?


Game:    http://static.pablofarias.com/blocked-down/

//this game will have only 1 statevar GameState = {  //load the game assets before the game starts  preload: function() {    this.game.load.image('ground', 'assets/images/ground.png');        this.game.load.image('platform', 'assets/images/platform.png');        this.game.load.image('player', 'assets/images/player.png');        this.game.load.image('fire', 'assets/images/fire.png');        this.game.load.image('goal', 'assets/images/goal.png');          },  //executed after everything is loaded  create: function() {    //adapt to screen size, fit all the game    this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;    this.scale.setScreenSize(true);    //init physics system    this.game.physics.startSystem(Phaser.Physics.ARCADE);    //floor    this.ground = this.game.add.sprite(0, 569, 'ground');    //enable physics properties (the floor wont move)    this.game.physics.arcade.enable(this.ground);    this.ground.body.immovable = true;    //level data. location of elements    var levelData = {      platformData: [        {x: 0, y: 430},        {x: 90, y: 290},        {x: 0, y: 140}      ],      fireData: [        {x: 200, y: 539},        {x: 60, y: 400},        {x: 190, y: 400},        {x: 180, y: 260},        {x: 300, y: 260},        {x: 200, y: 110}      ]    };        //group to keep all the hard platforms    this.platforms = this.game.add.group();    //enable physics properties    this.platforms.enableBody = true;    //create each platform    var self = this;    var platform;    levelData.platformData.forEach(function(element){      platform = self.platforms.create(element.x, element.y, 'platform');      //we don't need to enable body on each element, as we enabled body for the entire group, so body will be present here      platform.body.immovable = true;    });    //group for fire    this.fires = this.game.add.group();    this.fires.enableBody = true;    //create fire    var fire;    levelData.fireData.forEach(function(element){      fire = self.fires.create(element.x, element.y, 'fire');    });    //create goal    this.goal = this.game.add.sprite(20, 90, 'goal');    this.game.physics.arcade.enable(this.goal);    //create player    this.player = this.game.add.sprite(20, 535, 'player');    this.game.physics.arcade.enable(this.player);    this.player.body.gravity.y = 1000;    //don't leave the world boundaries    this.player.body.collideWorldBounds = true;    //arrow keys    this.cursors = this.game.input.keyboard.createCursorKeys();  },  update: function() {    //the player collides with the ground and platforms    this.game.physics.arcade.collide(this.player, this.ground);    this.game.physics.arcade.collide(this.player, this.platforms);    this.game.physics.arcade.overlap(this.player, this.fires, this.burn, null, this);    this.game.physics.arcade.overlap(this.player, this.goal, this.win, null, this);    //platformer controllers    this.player.body.velocity.x = 0;    if(this.cursors.left.isDown) {      this.player.body.velocity.x = -350;    }    else if(this.cursors.right.isDown) {      this.player.body.velocity.x = 350;    }    if(this.cursors.up.isDown && this.player.body.blocked.down) {      this.player.body.velocity.y = -550;    }  },  //burn player  burn: function(player, fire) {    console.log('auch!');  },  //win the game  win: function() {    console.log('you win');  },  render: function() {    this.game.debug.bodyInfo(this.player, 0, 100);  }};//initiate the Phaser frameworkvar game = new Phaser.Game(750, 640, Phaser.AUTO);game.state.add('GameState', GameState);game.state.start('GameState');
Link to comment
Share on other sites


  • Recently Browsing   0 members

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