From: MegaBrutal Date: Mon, 18 Apr 2016 14:44:32 +0000 (+0000) Subject: Update player's hitbox after shapeshifting X-Git-Tag: last-with-svg~2 X-Git-Url: http://git.megabrutal.com/?p=shapeshift.git;a=commitdiff_plain;h=fb04337a46e5c0dac80e7d26e69b47f6a398d524 Update player's hitbox after shapeshifting It was a known bug that the player's hitbox didn't change after the player shapeshifted into a new form. Now this is fixed. modified: shapeshift.js --- diff --git a/shapeshift.js b/shapeshift.js index e59f65c..d960d62 100644 --- a/shapeshift.js +++ b/shapeshift.js @@ -1,6 +1,7 @@ window.onload = function() { var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var ground; var platforms; var guards; var guard1, guard2; @@ -90,7 +91,7 @@ platforms.enableBody = true; - var ground = game.add.tileSprite(0, game.world.height - 80, game.world.width, 200, 'ground'); + ground = game.add.tileSprite(0, game.world.height - 80, game.world.width, 200, 'ground'); platforms.add(ground); ground.body.immovable = true; @@ -184,6 +185,11 @@ player.shape = SHAPE_GIRL; player.loadTexture('player_girl'); } + + player.body.setSize(player.texture.width, player.texture.height); + if ((ground.y - player.y) < player.body.halfHeight) + player.y = ground.y - player.body.halfHeight; + lastkeytime = game.time.now; }