Jump to content

player.body.onfloor and player.body.onCeiling not working together?


WelliXL
 Share

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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