Posts

Showing posts from September, 2017

LibGDX, Preferences, and Android

Another day of coding with LibGDX, another annoying Android issue. This time, it involves a Preferences object. I have a settings menu where the user can adjust things like sound effects volume, etc. There is a single Preferences object that lasts the entire lifetime of the game. In the settings menu, I read from and write to this object. And obviously I read the values elsewhere for the settings to take effect. A Preferences object is a simple key/value store with a "flush" method for persistence. Great, I figure. I can write to this thing, read from it, and persist it when needed. So, my approach to the settings menu is for the widget callback to write values to the persistence object. I.e., when a slider is slid, the callback grabs the new value of the slider. It then assigns this value to the relevant key in the preferences object. Then, any runtime state that needs realtime updating (e.g. music volume) can pick up these changes in their normal processing by reading t...