混合 Android 视图和 GLSurfaceView

2022-01-09 00:00:00 opengl-es android java

我目前正在开发一款游戏,我不想在进行到一半时发现我正在做的事情会导致错误/扼杀性能.这就是我正在考虑的设置方式.

I'm currently working on a game and I would hate to get halfway through and find that the what I'm doing causes errors/kills performance. This is how I'm thinking of setting it up.

首先想要一个带有一个包含 HUD 的 LinearLayout 的 LinearLayout,然后是一个 GLSurfaceView.但是我可能会在某些时候暂停"游戏视图并切换到包含库存或装备等的不同线性布局.

First want to have a LinearLayout with a LinearLayout containing a HUD, and then a GLSurfaceView. However I may at certain points "pause" the game view and switch to a different linear layout containing an inventory or equips, etc.

我认为这种方式最好,因为我可以利用 android 自带的所有优秀组件,而不是使用 OpenGL 自己制作.但是我担心混合这两种视图可能会出现一些问题.任何见解或建议将不胜感激.谢谢.

I think this way would be best because I can make use of all the great components that android comes with rather than making my own with OpenGL. However I am worried that mixing the two types of view may have some problems. Any insight or suggestions would be greatly appreciated. Thanks.

推荐答案

我一直在使用带有 GLSurfaceView 作为第一个元素的 FrameLayout.IE.在堆栈的底部,其他视图/视图组位于其顶部.我建议只是暂停游戏循环并在其顶部放置一些不透明的视图以隐藏它,而不是交换视图或其他任何东西:

I've been using a FrameLayout with the GLSurfaceView as the first element. I.e. at the bottom of the stack, with other views / viewgroups layered over the top of it. I'd recommend just pausing the game-loop and placing some opaque view over the top of it to hide it rather than swapping views in and out or whatever:

<FrameLayout 
    android:id="@+id/graphics_frameLayout1" 
    android:layout_width="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent">
    <android.opengl.GLSurfaceView 
        android:id="@+id/graphics_glsurfaceview1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
    </android.opengl.GLSurfaceView>
    <LinearLayout 
        android:layout_height="fill_parent" 
        android:id="@+id/inventory" 
        android:gravity="center" 
        android:layout_width="fill_parent" 
        android:orientation="vertical"
        android:visibility="gone">
    </LinearLayout>
    <LinearLayout 
        android:layout_height="fill_parent" 
        android:id="@+id/HUD" 
        android:gravity="center" 
        android:layout_width="fill_parent" 
        android:orientation="vertical">
    </LinearLayout>
</FrameLayout>

相关文章