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

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...