Jump to content

Lower Y Axis Border Detection


mpaarating
 Share

Recommended Posts

So I'm making a game that has "falling" items. For every item you miss it subtracts from your score (that goes up when you "catch" the items). I'm having trouble getting phaser to detect when the falling sprites fall past the lower visible of the y axis. I was doing something like:

function coinLost () {    if (coins.y > 600){        console.log("hit");    score -= (Math.floor(Math.random() * 10) + 1);    scoreField.content = 'Dollaz: $' + score;    }    if (score < 0)    {        gameOver();    }}function gameOver () {    introText = game.add.text(game.world.centerX, 400, 'Game Over', { font: "40px Arial", fill: "#ffffff", align: "center" });    introText.anchor.setTo(0.5, 0.5);}

This is outside of update. Should it be inside of update?

Link to comment
Share on other sites

I got it working by using this inside of my update function

    coins.forEach(function(coin){        if (coin.y > 100 && coin.alive){            console.log("hit");            score -= (Math.floor(Math.random() * 10) + 1);            scoreField.content = 'Dollaz: $' + score;            coin.kill();            //coins.remove(coin);        }        if (score < 0)        {            gameOver();        }    });

Thanks for the help!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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