Java Code Examples for com.badlogic.gdx.Preferences#putInteger()

The following examples show how to use com.badlogic.gdx.Preferences#putInteger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameOverScreen.java    From libgdx-2d-tutorial with MIT License 6 votes vote down vote up
public GameOverScreen (SpaceGame game, int score) {
	this.game = game;
	this.score = score;
	
	//Get highscore from save file
	Preferences prefs = Gdx.app.getPreferences("spacegame");
	this.highscore = prefs.getInteger("highscore", 0);
	
	//Check if score beats highscore
	if (score > highscore) {
		prefs.putInteger("highscore", score);
		prefs.flush();
	}
	
	//Load textures and fonts
	gameOverBanner = new Texture("game_over.png");
	scoreFont = new BitmapFont(Gdx.files.internal("fonts/score.fnt"));
	
	game.scrollingBackground.setSpeedFixed(true);
	game.scrollingBackground.setSpeed(ScrollingBackground.DEFAULT_SPEED);
}
 
Example 2
Source File: FramePropertiesPersister.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public static void saveFrameProperties(JFrame frame) {
    int extendedState = frame.getExtendedState();
    boolean extendedStateChanged = false;
    if (extendedState != Frame.NORMAL) {
        frame.setExtendedState(Frame.NORMAL);
        extendedStateChanged = true;
    }

    Preferences prefs = Gdx.app.getPreferences(PREF_NAME);
    prefs.putInteger("x", frame.getX());
    prefs.putInteger("y", frame.getY());
    prefs.putInteger("width", frame.getWidth());
    prefs.putInteger("height", frame.getHeight());
    prefs.putInteger("extendedState", extendedState != Frame.ICONIFIED ? extendedState : Frame.NORMAL); // Do not save Frame.ICONIFIED
    prefs.flush();

    if (extendedStateChanged) {
        frame.setExtendedState(extendedState);
    }
}
 
Example 3
Source File: WindowParamsPersistingApplicationWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
private void saveWindowParams() {
    int width = Display.getWidth();
    int height = Display.getHeight();
    int x = Display.getX();
    int y = Display.getY();

    //FIXME For some reason actual window position shifted by 6 pixels on Windows (by 12 at y when maximized).
    if (LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS) {
        x += 6;
        y += 6;
    }

    Preferences prefs = Gdx.app.getPreferences("window_params.xml");
    prefs.putInteger("x", x);
    prefs.putInteger("y", y);
    prefs.putInteger("width", width);
    prefs.putInteger("height", height);
    prefs.flush();
}
 
Example 4
Source File: GlobalConfiguration.java    From SIFTrain with MIT License 6 votes vote down vote up
public static void storeConfiguration() {
    Preferences prefs = Gdx.app.getPreferences("sif_train_config");
    prefs.putInteger("offset", offset);
    prefs.putInteger("input_offset", inputOffset);
    prefs.putInteger("song_vol", songVolume);
    prefs.putInteger("feedback_vol", feedbackVolume);
    prefs.putString("path_to_beatmaps", pathToBeatmaps);
    prefs.putBoolean("play_hint_sounds", playHintSounds);
    prefs.putInteger("note_speed", noteSpeed);
    prefs.putInteger("overall_difficulty", overallDifficulty);
    prefs.putInteger("sorting_mode", sortMode);
    prefs.putInteger("random_mode", randomMode);
    prefs.putInteger("sorting_order", sortOrder);
    prefs.putInteger("sync_mode", syncMode);
    prefs.flush();
}
 
Example 5
Source File: onScreenControls.java    From killingspree with MIT License 5 votes vote down vote up
public void resize() {
    Preferences prefs = Gdx.app.getPreferences("settings");
    int scaling = prefs.getInteger("scaling");
    if (scaling <= 30 || scaling >= 150) {
        scaling = 100;
        prefs.putInteger("scaling", 100);
        prefs.flush();
    }
    float buttonSize = (BUTTON_SIZE * (float) Gdx.graphics.getWidth() *
            scaling) / (1280f * 100f);
    shootButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
            buttonSize, buttonSize, buttonSize);
    jumpButton.setBounds(Gdx.graphics.getWidth() - 2 * buttonSize, 10,
            buttonSize, buttonSize);
    throwBombButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
            2f * buttonSize  * 1.1f, buttonSize, buttonSize);
    closeButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
            Gdx.graphics.getHeight() - buttonSize * 1.1f, buttonSize,
            buttonSize);
    buttonSize *= 0.8f;
    leftButton.setBounds(buttonSize * 0.1f,
            buttonSize * 0.1f, buttonSize, buttonSize);
    upButton.setBounds(buttonSize * 1.6f / 2,
            buttonSize, buttonSize, buttonSize);
    rightButton.setBounds(buttonSize * 1.6f,
            buttonSize * 0.1f, buttonSize, buttonSize);
}
 
Example 6
Source File: GameManager.java    From martianrun with Apache License 2.0 5 votes vote down vote up
public void saveScore(int score) {
    Preferences preferences = getPreferences();
    int maxScore = preferences.getInteger(MAX_SCORE_PREFERENCE, 0);
    if (score > maxScore) {
        preferences.putInteger(MAX_SCORE_PREFERENCE, score);
        preferences.flush();
    }
}
 
Example 7
Source File: GameManager.java    From martianrun with Apache License 2.0 5 votes vote down vote up
public void incrementAchievementCount(String id, int steps) {
    Preferences preferences = getPreferences();
    int count = preferences.getInteger(getAchievementCountId(id), 0);
    count += steps;
    preferences.putInteger(getAchievementCountId(id), count);
    preferences.flush();
}