2016-09-25 4 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에서 작동합니다.

관련 문제