praine Posted January 26, 2017 Share Posted January 26, 2017 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 Link to comment Share on other sites More sharing options...
drhayes Posted January 26, 2017 Share Posted January 26, 2017 Just checking, but... Beware of console logging properties off references that you later expand in the dev console. In other words, when you log "console.log(sprite.body.onTop());" inside that collision handler does it still tell you false? Link to comment Share on other sites More sharing options...
praine Posted January 27, 2017 Author Share Posted January 27, 2017 Hi drhayes, thanks for your reply. I don't seem to have that method available, I only have "onFloor" and "onWall" (Phaser 2.1.2) Link to comment Share on other sites More sharing options...
praine Posted January 27, 2017 Author Share Posted January 27, 2017 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 More sharing options...
drhayes Posted January 27, 2017 Share Posted January 27, 2017 You're right! The console is maintaining a reference and operating on that rather than presenting a value-in-time. One thing I've done if I really by FSM need a whole complicated object is to do "console.log(JSON.stringify(obj));". praine 1 Link to comment Share on other sites More sharing options...
Recommended Posts