in the class GameScreen I wrote this code for a score:
if (Gdx.input.justTouched()&& executed==true) {
MyGdxGame.camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
for (int i=0;i<4;i++) {
if (sprite[zahl[i]].getBoundingRectangle().contains(touchPoint.x, touchPoint.y) && zahl[4] == zahl[i]) {
int scoreValue = Integer.parseInt(score);
scoreValue++;
score = String.valueOf(scoreValue);
executed= false;
}
if (sprite[zahl[i]].getBoundingRectangle().contains(touchPoint.x, touchPoint.y) && zahl[4] != zahl[i]){
this.dispose();
game.setScreen(new GameOverScreen(game));
return;
}
}
}
The second if
refers to the class GameOverScreen
. So if a user loses the game, the GameOverScreen
would be shown. Now I want to show the reached score on the GameOverScreen
. Therefore I have to use the changing variable score
from the GameScreen
class in the GameOverScreen
class.
My question is: How can I use variables through different classes?