Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How to detect whether player hit tile from underneath?


praine
 Share

Recommended Posts

Hi All,

I have a Mario-esque game where player can run around and punch boxes from underneath to get rewards. I am setting up the tile layer with:

pf.boxes = pf.map.createLayer('boxes');
pf.map.setCollisionBetween(1, 5000, true, 'boxes');

Then I'm doing:

pf.game.physics.arcade.collide(pf.adventurer, pf.boxes, pf.hitbox, null, this);

on the update loop to handle the collision with boxes.

The "hitbox" function receives the player object and the tile object thusly:

hitbox:function(sprite,tile){
		console.log(sprite,tile);
	},

 

The output of sprite.body.touching gives false for all directions, and sprite.body.blocked gives true for down, so it's as if I'm not getting a readout of the player object at the time when it collided with the box, but rather after it landed back on the ground.

How do I get a readout of the player object at the time it actually hit the box?

Thanks in advance,

Paul

Screen Shot 2017-01-26 at 16.43.48.png

Link to comment
Share on other sites

Hi again, I'm now console logging sprite.body.blocked.up and it gives true when hitting the tile from below, but when logging the whole sprite object and expanding the body.blocked property, it gives false. Hmm. I always thought console.log() gave the value of objects at the time the method was called, but it seems to be giving the value at a later time.. perhaps when the property is expanded?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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