Sign in to follow this  

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?



//this game will have only 1 statevar GameState = {  //load the game assets before the game starts  preload: function() {'ground', 'assets/images/ground.png');'platform', 'assets/images/platform.png');'player', 'assets/images/player.png');'fire', 'assets/images/fire.png');'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;    //floor    this.ground =, 569, 'ground');    //enable physics properties (the floor wont move);    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 =;    //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.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 =, 90, 'goal');;    //create player    this.player =, 535, 'player');;    this.player.body.gravity.y = 1000;    //don't leave the world boundaries    this.player.body.collideWorldBounds = true;    //arrow keys    this.cursors =;  },  update: function() {    //the player collides with the ground and platforms, this.ground);, this.platforms);, this.fires, this.burn, null, this);, this.goal,, 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() {, 0, 100);  }};//initiate the Phaser frameworkvar game = new Phaser.Game(750, 640, Phaser.AUTO);game.state.add('GameState', GameState);game.state.start('GameState');

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.