2016-09-25 12 views
0

私はAndroidのゲームにLibgdxを使用しています。ユーザーの携帯電話のローカルストレージに保存ファイルを作成したいのですが、どうすればいいのでしょうか? https://developer.android.com/guide/topics/data/data-storage.html#filesInternalのような私が読んだ文書の中には、あまり曖昧なものがあり、私は実際に何が起こっているのか分かりませんし、自分のゲームでその事例を作ることもできます。この機能はLibgdx自体にありますか?デバイスのローカルストレージにAndroid保存ファイルを作成しますか?

答えて

2

libgdxのデータを格納するために、 "Preference"を使用します。デバイス自体にデータを格納するのに役立ちます。ここではデービスのメモリにデータを格納する例を示します。

  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

ありがとうございました。 –

0

あなたが探しているものはPreferencesだと思います。これは、アプリケーションのためにデータを保存する方法であり、iOSとAndroidで動作します。

関連する問題