1

How can we mult-thread in libgdx ?

I tried:

new Thread(new Runnable() {
   @Override
   public void run() {
      // do something important here, asynchronously to the rendering thread
      final int result = 10;
      // post a Runnable to the rendering thread that processes the result
      Gdx.app.postRunnable(new Runnable() {
         @Override
         public void run() {
            Array<Integer> results = new Array<Integer>;
            Gdx.app.log("Thread1", "Worked");
            results.add(result);
         }
      });
   }
}).start();

I have read here and it is official. But it did not tell me specifically how to access the array.

How can I access the result? through postRunnable

Fish
  • 1,689
  • 1
  • 18
  • 28

1 Answers1

3

You could subclass Runnable and keep the array as a member in that new subclass, there is a nice explanation for that approach here https://stackoverflow.com/a/7762490/4802055

Community
  • 1
  • 1
daniq
  • 151
  • 4