4.6、Libgdx線程介紹,4.6libgdx線程

來源:互聯網
上載者:User

4.6、Libgdx線程介紹,4.6libgdx線程
(原文:http://www.libgdx.cn/topic/48/4-6-libgdx%E7%BA%BF%E7%A8%8B%E4%BB%8B%E7%BB%8D)所有的ApplicationListener方法都在同一線程中調用。這個線程是可以調用OpenGL的渲染線程。對大部分遊戲來說,更新邏輯或者渲染一般都放在ApplicationListener.render()方法中。
任何的映像操作都會在渲染線程中操作,在其他線程中造作會導致未定義的行為,這是因為OpenGL context僅僅在渲染進程中可用。
為了從其他線程中傳遞資料到渲染進程中,我們推薦使用Application.postRunnable()。這將使得會在渲染進程的下一幀運行這些代碼,而且是在ApplicationListener.render()被調用之前。new Thread(new Runnable() {
@Override
public void run() {
// 在這完成需要的操作,同步到渲染線程。
final Result result = createResult();
// 將Runnable推送到渲染線程。
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
// 產生結果
results.add(result);
}
});
}
}).start();那個Libgdx類是安全執行緒的?
在Libgdx中,沒有類是安全執行緒的。除非在官方API中表明。記住,不要把graphics和audio相關的任何操作使用多線程。
(www.libgdx.cn著作權,如需轉載,註明出處)


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.