Search the Community
Showing results for tags 'onceiling'.
-
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(); }