KnTproject Posted November 2, 2016 Share Posted November 2, 2016 Hello, I want to add a score to my phaser game. My game is a road with a lot of cars that you have to avoid. My game goes from top of the screen (-400) to down (200). Now I have that if the car is from the screen, it has to kill the actual car. And if that car is killed, then the score +1. My car is this.auto This is my code in the create function: this.score = 0; this.labelScore = game.add.text(20, 20, "0", { font: "30px Arial", fill: "#ffffff" }); This is my code in the update function: if(this.auto.body.velocity.y > 300){ this.auto.kill(); addScore(); } This is my code in de addScore function: addScore:function(){ if(this.auto.kill() == true){ this.labelScore.text = this.score; this.score += 1; } }, But it doesn't work. I don't know if its the kill of the text that doesn't work. Does anybody knows what the problem is? Link to comment Share on other sites More sharing options...
Taggrin Posted November 3, 2016 Share Posted November 3, 2016 You can check if a certain function is called by adding a console.log and check your browser console. Anyway, what I always use for updating text is the following: labelScore.setText(score); Never used <object>.text so not sure if that would matter, but you can try I guess. I would also recommend to change your score before changing your text, otherwise it will always be 1 behind . Link to comment Share on other sites More sharing options...
Recommended Posts