-
Notifications
You must be signed in to change notification settings - Fork 0
Preferences
Preferences are a simple way to store small data for your application, e.g. user settings, small game state saves and so on. Preferences work like a hash map, using strings as keys, and various primitive types as values. Preferences are also the only way to date to write persistent data when your application is run in the browser.
Preferences are obtained via the following snippet:
Preferences prefs = Gdx.app.getPreferences("My Preferences");
Note that your application can have multiple preferences, just give them different names.
Modifying preferences is as simple as modifying a Java Map:
prefs.putString("name", "Donald Duck");
String name = prefs.getString("name", "No name stored");
prefs.putBoolean("soundOn", true);
prefs.putInteger("highscore", 10);
Note that getter methods come in two flavors: with and without a default value. The default value will be returned if there is no value for the specified key in the preferences.
Your changes to a preferences instance will only get persisted if you explicitly call the flush()
method.
// bulk update your preferences
prefs.flush();
On Windows, Linux, and OS X, preferences are stored in an xml file within the user's home directory.
OS | Preferences storage location |
---|---|
Windows | %UserProfile%/.prefs/My Preferences |
Linux and OS X | ~/.prefs/My Preferences |
The file is named whatever you passed to Gdx.app.getPreferences()
.
This is useful to know if you want to change or delete them manually for testing.
On Android, the system's SharedPreferences class is used. This means preferences will survive app updates, but are deleted when the app is uninstalled.
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * Viewports * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics * Quick Start * Models * Material and environment * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)