我爲Android製作了一個基本的3D遊戲,並希望添加HUD。我應該怎麼做?是否有可能在3D遊戲之上添加一個佈局,或者我必須使用OpenGL來做到這一點?Android:通過OpenGL-ES遊戲(HUD)的圖像
0
A
回答
1
典型的解決方案是繪製3D場景,然後切換到正交投影並使用OpenGL繪製HUD。將普通組件放在OpenGL畫布上可能會產生不可預知的結果(它們可能閃爍或僅僅是不可見)。
2
可以在openGL佈局上添加一個或多個佈局。要做到這一點,你必須從RelativeLayout開始。它將包含OpenGL和Hud佈局。聲明順序很重要(首先聲明,首先呈現)。要更改Hud佈局的位置,可以使用layout_margin屬性,或者如果它是完整的疊加層,則使用match_parent。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- START of OpenGL Layout -->
<LinearLayout
android:id="@+id/openGLLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp" >
</LinearLayout>
<!-- END of OpenGL Layout -->
<!-- START of HUD Layout -->
<LinearLayout
android:id="@+id/hudLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp">
<TextView
android:id="@+id/hudText"
android:text="Hud Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
<!-- END of HUD Layout -->
</RelativeLayout>
在這個例子中,OpenGL佈局是一個empy LinearLayout作爲容器使用。添加自己的GLSurfaceView這個RelativeLayout的由代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main);
MyOpenGLSurfaceView view = new MyOpenGLSurfaceView(getApplication());
LinearLayout openGLLayout = (LinearLayout)findViewById(R.id.openGLLayout);
openGLLayout.addView(mView);
}
我主要用這個方法進行確認彈出窗口或上下文菜單。這樣我就不必使用openGL創建自己的按鈕。
0
我遇到了同樣的問題,現在我打了近一年。我沒有使用XML的佈局,而是我添加的意見在Java中,像這樣:
,我得到了rel.addView(camPreview, camParams);
rel.addView(glView, glParams);
rel.addView(imageView, imageParams);
一個建議是,增添AZ索引參數去的addView調用像這樣:
rel.addView(camPreview, 0, camParams);
rel.addView(glView, 1, glParams);
rel.addView(imageView, 2, imageParams);
,但沒有工作,要麼..
我甚至嘗試切換到XML佈局,但仍然沒有什麼,我到底該解決方案是希望
:
glView.setZOrderMediaOverlay(true);
rel.addView(camPreview, camParams);
rel.addView(glView, glParams);
rel.addView(imageView, imageParams);
注:setZOrderMediaOverlay(真),需要在您實際上添加視圖
嘗試,讓我知道這是否爲你的作品被調用。
相關問題
- 1. 遊戲用戶界面HUD
- 2. 無法通過遊戲層調用HUD層方法Cocos2d
- 3. Android遊戲圖像格式
- 4. Android存儲益智遊戲的圖像
- 5. Opengl在3D遊戲中繪製HUD
- 6. Android中的像素遊戲
- 7. OPENGLES遊戲每3秒鐘凍結
- 8. Android遊戲中的通知
- 9. 調試一些opengles與eclipse的android遊戲遇到outofmemoryerror異常
- 10. Cocos2d-x:通過圖像繪製遊戲中的生命數量
- 11. Android - 通過觸摸選擇遊戲板中的圖塊?
- 12. 益智遊戲與圖像像15-益智(十五的遊戲)
- 13. Android TextView鏡像(hud)?
- 14. 遊戲多圖片的Android
- 15. Android交通遊戲開發
- 16. 如何通過按鍵Java 2D遊戲動畫圖像?
- 17. [Android]比較兩個圖像/繪圖在Android的記憶遊戲?
- 18. 通過遊戲中心
- 19. 通過PhoneGap構建遊戲
- 20. 安卓遊戲圖像
- 21. 旋轉圖像遊戲
- 22. 通過遊戲中心分享保存的遊戲數據?
- 23. Android遊戲點繪圖
- 24. Android的帆布遊戲,遊戲速度
- 25. 如何通過C++中的OpenGLES在android中顯示位圖?
- 26. 與Android遊戲
- 27. Android HTML5遊戲
- 28. android opengl遊戲
- 29. 在Pong遊戲中通過槳的球
- 30. android中的遊戲