我在Android上使用Libgdx進行遊戲,並且我想在用戶手機的本地存儲上創建一個保存文件,而且我想知道如何去做這件事。我讀過的一些文件如:https://developer.android.com/guide/topics/data/data-storage.html#filesInternal一直都很模糊,我不太明白髮生了什麼,或者可以讓我的例子在我自己的遊戲中運行。 Libgdx本身有這個功能嗎?在設備的本地存儲上創建Android保存文件?
0
A
回答
2
在libgdx中用於存儲我們使用「偏好」的數據。這有助於將數據存儲在設備本身中。在這裏我會給你一個例子來存儲在deveice內存中的數據。
myGame extends ApplicationAdapter{
public static int count;
public static bitmapFont font;
public SpriteBatch batch;
public static Preferences prefs;
public void create()
{
batch=new SpriteBatch();
font=new font(Gdx.files.internla("myFont.png"));
public static Preferences prefs;
// this is for setting up the storage for the current project
prefs = Gdx.app.getPreferences("myGame");
}
public void incrementCount()
{
count++;
if(count>100){
// here "countValue" is the key(which is the reference to the data) and "count" is the vlaue(the data). the value is stored in key value method.
prefs.putInteger("countValue", count);
// is used to flush the data in to the storage
prefs.flush();
}
public void render()
{
// getting the stored value from the preference
pref.getInteger("countValue",countValue);
batch.begin();
batch.draw(font,countValue+"stored value",0,0)
batch.end()
}
// this is the simple way to store the data into the device memory . it will work in both the android and the IOS
0
我認爲你要找的是Preferences。這是爲您的應用程序存儲數據的一種方式,適用於iOS和Android。
相關問題
- 1. 在Android設備上創建和存儲日誌文件
- 2. 用Ionicframework創建本地存儲(設備,而不是緩存)
- 3. 創建假存儲設備
- 4. Android和LibGDX:在本地存儲中創建XML文件
- 5. 保存在本地存儲
- 6. Android:將android設備的內部存儲器中的文本文件存儲在外部存儲卡中?
- 7. 保存日誌文本文件的設備時,關閉在Android
- 8. 從上傳文件創建Base64而不保存在本地php
- 9. 在android studio的本地存儲上保存小字符串
- 10. 在Android設備上創建文件
- 11. 在Linux上創建href鏈接到本地可移動存儲設備
- 12. 無法在移動設備上設置本地存儲,反應
- 13. 在本地保存文件
- 14. Android設備上的大容量存儲
- 15. 以編程方式在Android設備上保存文件
- 16. PhoneGap - JSON本地存儲在設備上的數據
- 17. 在Android的內部存儲上保存文件
- 18. Android:無法看到保存在外部存儲上的文件
- 19. 在Artifactory中創建本地存儲庫
- 20. 如何在android設備上安全地存儲信息?
- 21. 訪問在Android設備上保存到內部存儲的數據
- 22. 將本地存儲模型保存到本地存儲
- 23. 我如何保存在本地存儲
- 24. 創建pom.xml文件存儲在本地資源庫
- 25. 在Hudson上存儲由python腳本創建的csv文件
- 26. android - 保存文件到內部存儲
- 27. Android創建一個存儲的設置
- 28. 創建xml文件並將其保存在內部存儲器中android
- 29. 內部存儲Android - 設備內存
- 30. 無法在外部存儲器上創建文件Android
感謝您的幫助。 –