jPCT-AE - a 3d engine for Android > Support

To another View and back?

(1/2) > >>

EgonOlsen:
Has anybody an idea how to replace the GLSurfaceView with another View and make it render again after the other View is done?

What i'm trying to do, is to open another View (defined in a layout.xml file) when pressing OK (on the phone). This actually works fine. When i press OK, i set the content view to the new view, the GLSurfaceView obviously stops doing rendering and i can use the GUI in the new View. After pressing a button, i want to return to the GLSurfaceView and continue rendering. It tried this by doing another setContentView(...), this time with the GLSurfaceView. This works to a degree. The GUI View goes away, the GLSurfaceView thread requests and gets the gl surface again (judging from the logs) and...nothing happens. The onDrawFrame()-method never gets called again!? Even if i enqueue something to be executed in the gl thread, this never happens.

I tried several other things like playing around with setVisibility(...) and stuff, but to no avail. I couldn't find any example in the sources and wasn't lucky on the net either.

Any ideas?

EgonOlsen:
I did some further debugging and obviously, setContentView() isn't the way to go. When doing this, the render thread gets stopped and never starts again. I can avoid this by overriding one method in GLSurfaceView, but then, the surface gets created again after returning to the render thread, which also isn't what i want. There has to be some other solution...

EgonOlsen:
Got it. This is my main.xml


--- Code: ---<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.opengl.GLSurfaceView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/surface_view" android:visibility="visible" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:id="@+id/mylayout"
android:visibility="invisible" android:background="#000000">

<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Options menu"
android:textStyle="bold"></TextView>

<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/backdrop"
android:text="Render backdrop"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/glows"
android:text="Render glow effects"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/particles"
android:text="Render particles"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/limiter"
android:text="Eco mode (fast devices only)"></CheckBox>
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Continue playing"></Button>
</LinearLayout>
</FrameLayout>

--- End code ---

In the onCreate()-method of the Activity, i'm now doing this:


--- Code: ---setContentView(R.layout.main);
mGLView = (GLSurfaceView) this.findViewById(R.id.surface_view);
....

--- End code ---

instead of the former:


--- Code: ---mGLView = new GLSurfaceView(getApplication());
...
setContentView(mGLView);

--- End code ---

When pressing the OK button, i'm doing this:


--- Code: ---final View v2=this.findViewById(R.id.mylayout);
mGLView.setVisibility(View.INVISIBLE);
v2.setVisibility(View.VISIBLE);

--- End code ---

...and when i'm done in the GUI View, i'm doing this in reverse...

My main fault before was, that i expected the View to be available via findViewById() in any case, but i always got "null", which was why i couldn't activate my GUI view...simply because i couldn't access it. The trick is to set the whole layout defined in the main.xml as content view. If you don't do this, you can't access neither the GLSurfaceView nor the GUI View.

raft:
so, you wont use a GL based gui in your game i suppose ? instead switch to an Android gui ?

EgonOlsen:
Not for the actual game menu, but the options menu is easier to do in an Android gui.

Navigation

[0] Message Index

[#] Next page

Go to full version