Regarding your latest issue (seeing NaN for the score on the game over screen), look at what your code is doing when the game ends:
- the Player class calls
Main.showGameOver()
- Player class makes a new game over screen
- Player class sets the final score on the new game over screen
In Main.showGameOver():
- you make a new game over screen and add it to the stage, but this is now a different game over screen than the one in your Player class
- this new game over screen never had the final score set (and therefore the score is
NaN
)
One way to address this:
- Remove all references to the game over screen from your Player class
- Modify the
showGameOver()
method in main so that it accepts the score - Modify the Player class so that is passes the final score using
Main.showGameOver()
- Modify the
showGameOver()
method in Main so that it sets the score on game over screen
Your modified code might look like this:
Player class:
public function showgameoverFunction(e:MouseEvent)
{
mainClass.showGameOver(gameScore.toString());
}
Main class:
public function showGameOver(finalScore:String)
{
gameOverClass = new thegameoverclass(this);
gameOverClass.setScoreText(finalScore);
addChild(gameOverClass);
removeChild(playClass);
playClass = null;
}