libgdx Preferences 使用
来源:互联网 发布:iphone自制铃声mac 编辑:程序博客网 时间:2024/06/05 08:26
demo里面可以看到:
关键代码为:
Preferences prefs = Gdx.app.getPreferences(".test"); 获取配置
prefs.putBoolean("bool", true); //写入数据
prefs.flush(); // 提交数据,重要。
源码为:
package com.badlogic.gdx.tests;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.tests.utils.GdxTest;
import com.badlogic.gdx.utils.GdxRuntimeException;
public class PreferencesTest extends GdxTest {
public void create () {
Preferences prefs = Gdx.app.getPreferences(".test");
if (prefs.contains("bool")) {
if (prefs.getBoolean("bool") != true) throw new GdxRuntimeException("bool failed");
if (prefs.getInteger("int") != 1234) throw new GdxRuntimeException("int failed");
if (prefs.getLong("long") != Long.MAX_VALUE) throw new GdxRuntimeException("long failed");
if (prefs.getFloat("float") != 1.2345f) throw new GdxRuntimeException("float failed");
if (!prefs.getString("string").equals("test!")) throw new GdxRuntimeException("string failed");
}
prefs.clear();
prefs.putBoolean("bool", true);
prefs.putInteger("int", 1234);
prefs.putLong("long", Long.MAX_VALUE);
prefs.putFloat("float", 1.2345f);
prefs.putString("string", "test!");
prefs.flush();
if (prefs.getBoolean("bool") != true) throw new GdxRuntimeException("bool failed");
if (prefs.getInteger("int") != 1234) throw new GdxRuntimeException("int failed");
if (prefs.getLong("long") != Long.MAX_VALUE) throw new GdxRuntimeException("long failed");
if (prefs.getFloat("float") != 1.2345f) throw new GdxRuntimeException("float failed");
if (!prefs.getString("string").equals("test!")) throw new GdxRuntimeException("string failed");
}
下载更多测试demo,请在:
http://download.csdn.net/detail/a332324956/7337225 下载即可。
0 0
- libgdx Preferences 使用
- (libgdx学习)Preferences
- (libgdx学习)Preferences
- Libgdx的Preferences
- 第七章 Libgdx之Preferences
- 使用Preferences
- LibGdx文档译读(十) Preferences接口
- java Preferences 使用
- Preferences.xml的使用
- android preferences使用
- Preferences...
- pReferences
- 7.Android Preferences的使用
- 使用Shared Preferences存储数据
- Android Preferences的基本使用
- 使用Shared Preferences存储数据
- LibGdx--在LibGdx中使用Toast
- Android上使用libgdx
- Linux C编程连载(4)-基于TCP/IP的文件传输系统
- [LeetCode]ZigZag Conversion
- easyui datagrid rowediting使用心得
- 关于C++中的拷贝构造和赋值重载的理解
- ArcGIS技术:将不小心移动的图斑放回原位置
- libgdx Preferences 使用
- JEECG-批量删除操作
- 1153
- 扩展Django:实现自己的manage命令
- GIS是怎样建成的之五:瓦片(Tile)
- eclipse主题与颜色主题的添加(实现黑色面板)
- c/c++全局变量与局部变量
- c_语法入门_day1
- VC2010 LINK:fatalerrorLNK1123:failureduringconversiontoCOFF:fileinvalidorcorrupt 问题解决