WelliXL Posted September 13, 2017 Share Posted September 13, 2017 Hi i'm very new to Phaser but i'm struggling with the onFloor and onCeiling events working together - i'm assuming it's syntax or something stopping this working as i want. Basically i'm playing with the sandbox and using code from the examples to familiarize myself with Phaser - my problem is this (code snippet from update below) the player.body.onFloor event works if i comment out the player.body.onCeiling event and a Game over message appears. As it is if i get the player to the top of the screen I get the You win message - but if i hit the floor then the game over message does not appear and the game seems to freeze and Platforms.destroy() does not execute. or is there a better way to implement "top" and "Bottom" of the screen? var text; var message; function update () { emitter.customSort(scaleSort, this); game.physics.arcade.collide(player, platforms); player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -250; } else if (cursors.right.isDown) { player.body.velocity.x = 250; } if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down)) { player.body.velocity.y = -400; } // mycode if (player.body.onFloor()) { message ="Game Over!"; GameOver(message); } if (player.body.onCeiling()) { message ="You Win!"; GameOver(message); } } function GameOver() { var bar = game.add.graphics(); bar.beginFill("#FFFFFF", 1); bar.drawRect(0, 250, 800, 100); var style = { font: "bold 32px Arial", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" }; text = game.add.text(0, 0, message, style); text.setShadow(3, 3, 'rgba(0,0,0,0.5)', 2); text.setTextBounds(0, 250, 800, 100); platforms.destroy(); player.destroy(); } Link to comment Share on other sites More sharing options...
WelliXL Posted September 13, 2017 Author Share Posted September 13, 2017 answer was staring me in the face! // mycode if (player.body.onFloor()) { message ="Game Over!"; GameOver(message); } else if (player.body.onCeiling()) { message ="You Win!"; GameOver(message); } Link to comment Share on other sites More sharing options...
samme Posted September 14, 2017 Share Posted September 14, 2017 23 hours ago, WelliXL said: but if i hit the floor then the game over message does not appear and the game seems to freeze and Platforms.destroy() does not execute. Check the browser console. Link to comment Share on other sites More sharing options...
Recommended Posts