Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package menu;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.Preferences;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.Animation;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.GlyphLayout;
- import com.badlogic.gdx.utils.Align;
- import com.badlogic.gdx.utils.ScreenUtils;
- import com.mygdx.game.MainGameScreen;
- import com.mygdx.game.MyGdxGame;
- import org.w3c.dom.Text;
- import java.awt.*;
- import java.util.ArrayList;
- public class MainMenuScreen implements Screen {
- MyGdxGame game; // a class where the SpriteBatch is created
- int highscore, score;
- BitmapFont scoreFont;
- public MainMenuScreen(MyGdxGame game) {
- this.game = game;
- Preferences prefs = Gdx.app.getPreferences("spacegame"); // this will create a file if not exist
- this.highscore = prefs.getInteger("highscore", 0); // this will read. if not exist default will be 0
- //Check if score beats highscore
- if (score > highscore) {
- prefs.putInteger("highscore", score); // putting new score
- this.highscore = score;
- prefs.flush();
- }
- scoreFont = new BitmapFont();
- }
- @Override
- public void show() {
- }
- @Override
- public void render(float delta) {
- ScreenUtils.clear(0, 1, 1, 1);
- game.batch.begin();
- GlyphLayout highScoreLayout = new GlyphLayout(scoreFont, "Highscore: " + highscore, Color.GOLD, 0, Align.left, false);
- scoreFont.draw(game.batch, highScoreLayout, 50, 600); // adding to screen
- game.batch.end();
- }
- @Override
- public void resize(int width, int height) {
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- @Override
- public void hide() {
- }
- @Override
- public void dispose() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement