Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I avoided this problem rather than solve it for my game:</p> <p>I use a 'FrameLayout' as the main layout, with the 'GLSurfaceView' as the first layout inside it (i.e. at the bottom of the stack), the 'menu' viewgroup next, and an opaque 'loading' screen top of it (set to <code>match_parent</code> to fill the screen):</p> <pre><code>&lt;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"&gt; &lt;android.opengl.GLSurfaceView android:id="@+id/graphics_glsurfaceview1" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;/android.opengl.GLSurfaceView&gt; &lt;LinearLayout android:id="@+id/menu_linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visiblility="gone" android:background="#000000"&gt;// opaque background // menus etc be here &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_height="fill_parent" android:id="@+id/loading_linearLayout1" android:layout_width="fill_parent" android:orientation="vertical" android:background="#000000"&gt;// opaque background &lt;ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/loading_progressBar1"&gt; &lt;/ProgressBar&gt; &lt;TextView android:layout_width="wrap_content" android:id="@+id/loading_textView1" android:layout_height="wrap_content" android:text="Loading..."&gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; &lt;/FrameLayout&gt; </code></pre> <p>When the loading has finished, I set the loading viewgroup to invisible or gone, and the menu viewgroup to visible. Once the user has selected the option to start the game, I start the game logic thread and make the menu gone again</p> <p>I have a hierarchy of activities (<code>ReTouchMenuActivity extends ReTouchActivity</code>, then in a new file, <code>ReTouchActivity extends RokonActivity</code>) so that I don't end up with the whole game in a single, unmanageable file</p> <p>I load other assets in separate threads (for example, vertex data for 3D models) and then load in the vertices, texture coords etc just prior to drawing arrays (i.e. <code>gl.glVertexPointer(3, GL10.GL_FLOAT, 0, meshVertices);</code></p> <p>The real problem is that you have to load the textures in the GL Thread, which can block the UI thread (though without crashing it) leading to no responsiveness to user input when loading large textures. My own game using the above on a ZTE Blade running android 2.1 can take up to two seconds to load some large textures (1mb+) and even the circular progress bar stops spinning during this time. </p> <p>I noticed you <code>finish()</code> the activity when the user clicks the quit button, but when the user leaves the app without clicking the quit button (say when they get an incoming call or select something from the notifications bar), the activity/app still runs in the background. You have to re-load textures when they bring the activity/app back to the top of the stack (i.e. the user re-opens it). If you don't re-load textures in such a scenario, the user will just get a load of blank instead of textures</p> <p>If you try saving as a variable the GL handle/object that android passes to your <code>Renderer</code> class' <code>onDraw</code> method, for use by a texture-loading thread for example, then it goes out of context after the <code>onDraw</code> method returns and texture loading fails.</p> <p>I assume is because android wipes all the graphics data / openGL state, when the user leaves the app, in case other apps want to use it. Therefore I assume you can't do precisely what you're aiming to do (preload textures in android os or whatever). Though if someone else knows better, I'd be interested in hearing.</p> <p>Edit:</p> <p><a href="https://stackoverflow.com/questions/8115941/loading-textures-at-random-place">This question</a> has some good answers about speeding up actual load time for textures</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload