libgdx - 如何访问postRunnable

时间:2015-04-17 17:02:07

标签: java multithreading libgdx

我们如何在libgdx中进行多线程?

我试过了:

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();

我已阅读here,这是正式的。但它没有具体告诉我如何访问阵列。

如何访问结果?通过postRunnable

1 个答案:

答案 0 :(得分:2)

您可以将Runnable子类化并将该数组保留为该新子类中的成员,这里有一个很好的解释https://stackoverflow.com/a/7762490/4802055