第五章(5)Libgdx应用框架之线程

Android游戏开发群:290051794
Libgdx游戏开发框架交流群:261954621 

 

所有的ApplicationListener方法都会在同一线程中调用,这个线程是OpenGL调用的渲染线程。对于大多数程序来说足够实现逻辑更新和ApplicationListener.render()中的渲染,在渲染进程中。

任何图形的操作直接涉及OpenGL在渲染线程中执行。在不同的线程中这样做会导致未知的问题。这是因为OpenGL环境仅仅会在渲染进程中激活。在不同进程中执行在很多Android设备中出现问题。所以不支持。

使用Application.postRunnable()将其他线程的数据传递到渲染线程。在ApplicationListener.render()调用之前,会在渲染线程的Runnable中运行代码。

 

 

 

 

new Thread(new Runnable() {

   @Override

   public void run() {

      // do something important here, asynchronously to the rendering thread

      final Result result = createResult();

      // post a Runnable to the rendering thread that processes the result

      Gdx.app.postRunnable(new Runnable() {

         @Override

         public void run() {

            // process the result, e.g. add it to an Array<Result> field of the ApplicationListener.

            results.add(result);

         }

      });

   }

}).start();


 

 作者:宋志辉 
出处:http://blog.youkuaiyun.com/song19891121
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 
支持: 新浪微博 腾讯微博

 

 

 

转载于:https://www.cnblogs.com/hainange/archive/2013/05/12/6153562.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值