简体   繁体   English

混合Android视图和GLSurfaceView

[英]Mixing Android Views and GLSurfaceView

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. 这就是我想要设置它的方式。

视图布局

First want to have a LinearLayout with a LinearLayout containing a HUD, and then a GLSurfaceView. 首先想要一个包含HUD的LinearLayout的LinearLayout,然后是一个GLSurfaceView。 However I may at certain points "pause" the game view and switch to a different linear layout containing an inventory or equips, etc. 但是我可能会在某些时候“暂停”游戏视图并切换到包含库存或装备等的不同线性布局。

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. 我认为这种方式最好,因为我可以使用Android附带的所有优秀组件,而不是使用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. 谢谢。

I've been using a FrameLayout with the GLSurfaceView as the first element. 我一直在使用FrameLayout和GLSurfaceView作为第一个元素。 Ie 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>

用于游戏的Android Framelayout。看看ma ms paint skillz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM