mpaarating Posted April 3, 2014 Share Posted April 3, 2014 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 More sharing options...
ram64 Posted April 3, 2014 Share Posted April 3, 2014 Try calling the coinLost() function from the update loop. valueerror 1 Link to comment Share on other sites More sharing options...
mpaarating Posted April 3, 2014 Author Share Posted April 3, 2014 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 More sharing options...
Recommended Posts