Sarahjdes Posted September 13, 2014 Share Posted September 13, 2014 This may be a very simple question. I have this basic platformer game. At the end, when the player reaches a certain x/y coordinate, the game ends. My endGame function looks like so : endGame: function(){ this.player.kill(); this.game.add.sprite(200,100,'congratulations'); }This function is called in the update part of my code : if(Math.round(this.player.position.x/32 + 1) == 12 && Math.round(this.player.position.y/32 + 1) <= 15) { this.endGame();}I am aware this may not be the cleanest and simplest way to do this, but I am fairly new to phaser. My problem is, as soon as the game ends, the 'congratulations' sprite is added 60 times per second, which is obviously considerably slowing my fps rate. How can I avoid this? Is there a way to add my sprite in the create part of my code, but only show it when the endGame sprite is called? Thanks! Link to comment Share on other sites More sharing options...
OscarBraindeaD Posted September 13, 2014 Share Posted September 13, 2014 Hi Sarahjdes,I'm a newbie in html5 game programming (in fact this is my first post here), but I would use a bool to see if the sprite was already created, something like: if(Math.round(this.player.position.x/32 + 1) == 12 && Math.round(this.player.position.y/32 + 1) <= 15 && this.endCalled==false) { this.endGame(); this.endCalled=true;} Using it, you only call one time the endGame() function. Of course, you must initialize this.enCalled to false when you began the level.I hope it helps and excume my english! Regards Link to comment Share on other sites More sharing options...
MorpheusZ Posted September 13, 2014 Share Posted September 13, 2014 2 possible solutions: (1)in create():congratsSprite.visible = false;in endGame():congratsSprite.visible = true; (2)in create():this.gameRunning = true;in update():if (this.gameRunning && <your win condition>) { this.gameRunning = false; this.endGame();} Link to comment Share on other sites More sharing options...
Sarahjdes Posted September 13, 2014 Author Share Posted September 13, 2014 Thanks to both of you! The sprite.visible was exactly what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts