Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make a pre-loader scene with a background. It will show a picture with your label or ad while the textures are loading. Also it makes your app more attractive.</p> <pre><code>public class Main extends BaseGameActivity { public static Camera mCamera; //Scenes public static MainState _MainState; private static Scene PreloaderScene; private static BitmapTextureAtlas Preloader_Texture; private static TextureRegion Preloader_TR; private static Sprite Preloader_Sp; private static boolean GameLoaded = false; public static Engine thisEngine; @Override protected void onCreate(final Bundle pSavedInstanceState) { super.onCreate(pSavedInstanceState); } @Override public Engine onLoadEngine() { mCamera = new Camera(0, 0, CommonValues.CAMERA_WIDTH, CommonValues.CAMERA_HEIGHT); return new Engine(new EngineOptions( true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CommonValues.CAMERA_WIDTH, CommonValues.CAMERA_HEIGHT), mCamera ).setNeedsSound(true).setNeedsMusic(true)); } @Override public void onLoadResources() { thisEngine = this.mEngine; thisEngine.enableVibrator(this); BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); Preloader_Texture = new BitmapTextureAtlas(512, 1024, TextureOptions.DEFAULT); Preloader_TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset( Preloader_Texture, Main.this, "menu/loading_scr.jpg", 0, 0 ); thisEngine.getTextureManager().loadTextures(Preloader_Texture); } public Scene onLoadScene() { PreloaderScene = new Scene(); PreloaderScene.setIgnoreUpdate(true); Preloader_Sp = new Sprite(0, 0, Preloader_TR); PreloaderScene.attachChild(Preloader_Sp); GameLoaded = false; // showing preloader scene and loading resources in asynctask IAsyncCallback callback = new IAsyncCallback() { @Override public void workToDo() { Textures.LoadTextures(Main.this); } @Override public void onComplete() { GameLoaded(); } }; //Fixed variant working with gles1 and gles2 runOnUiThread(new Runnable() { @Override public void run() { new AsyncTaskLoader().execute(callback); } }); //Старый вариант. Не работает в GLES2 //new AsyncTaskLoader().execute(callback); return PreloaderScene; } /** * Textures are loaded = hiding preloader and showing main scene */ protected void GameLoaded() { GameLoaded = true; _MainState = new MainState(Main.this); mEngine.setScene(_MainState); PreloaderScene = null; thisEngine.getTextureManager().unloadTextures(Preloader_Texture); Preloader_Texture = null; Preloader_Sp = null; _MainState.ShowMainScreen(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (_MainState != null) { _MainState.onKeyDown(keyCode, event); return true; } } return super.onKeyDown(keyCode, event); } @Override public void onLoadComplete() { } @Override public void onPauseGame() { super.onPauseGame(); if (!GameLoaded) return; if (_MainState != null) _MainState.PauseGame(); } @Override public void onResumeGame() { super.onResumeGame(); if (!GameLoaded) return; if (_MainState != null) _MainState.UnPauseGame(); } } public abstract void workToDo(); public abstract void onComplete(); } // class AsyncTaskLoader: public class AsyncTaskLoader extends AsyncTask&lt;IAsyncCallback, Integer, Boolean&gt; { IAsyncCallback[] _params; @Override protected Boolean doInBackground(IAsyncCallback... params) { this._params = params; int count = params.length; for (int i = 0; i &lt; count; i++) { params[i].workToDo(); } return true; } @Override protected void onPostExecute(Boolean result) { int count = this._params.length; for (int i = 0; i &lt; count; i++) { this._params[i].onComplete(); } } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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