The following code shows how I load the game Libgdx (MyGdxGame) in LinearLayout. on creating the game, I set up the camera and uploaded a small wav sound file. The texture is loaded after the view is loaded.
The problem is the passage of the fragment to this fragment, a noticeable black flash and delay are observed. Is it possible to reduce this somehow and improve the transition of the fragment.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = null; Bundle bundle = getArguments(); if (bundle != null) { this.input = bundle.getParcelable(Utils.FRAGMENT_INPUT_KEY); } else { input = new FragmentInput(); } view = inflater.inflate(R.layout.solve, container, false); surface = (LinearLayout) view.findViewById(R.id.puzzleView); activity = (MainActivity) getActivity(); com.badlogic.gdx.graphics.Color color = new com.badlogic.gdx.graphics.Color(Color.red(input.backColor) / 255f, Color.green(input.backColor) / 255f, Color.blue(input.backColor) / 255f, 1.0f); size = input.pieceCount; cols = input.columns; GameData gdata = new GameData(); gdata.rows = size / cols; gdata.columns = cols; gdata.backColor = color; gdata.setCategory(input.category); if (input.rotated) { gameView = new MyGdxGameRotate(this, gdata); } else { gameView = new MyGdxGame(this, gdata); } if (surface != null) { AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); View game = initializeForView(gameView, config); surface.addView(game); } return view; }
onCreateViewcalled before the fragment is shown, doing the hard work here means that you are delaying the display of this view (“black flash”), instead you should start by transferring the hard work to onResumeor at leastonViewCreated
onCreateView
onResume
onViewCreated
-, , . Android - AsyncTask, , .
public void onViewCreated() { new AsyncTask<Void, Void, Void>() { public Void doInBackground() { //Do your loading } public void onPostExecute(Void aVoid) { //Update display, play sound (on resumed fragment) } }.execute(); }
Android,
Libgdx, Libgdx. , , , , Framelayout ImageView, puzzleView, , xml. onCreateView , , puzzleView, . , , onResume ( ), , , , puzzleView. - , , onResume() , () . , , , , , onCreateView, ( ) Runnable, runOnUiThread() .
Source: https://habr.com/ru/post/1694448/More articles:Nested generics in function definition in TypeScript - typescriptUnsuccessful responsive navigator - htmlНастройте UILabel на размер содержимого с автозапуском в iOS - iosSearch unique for each group with filter - rHow can I repeat a specific iteration in a foreach loop in PHP? - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1694449/allow-access-to-certain-locations-via-ip-whitelist-only-in-nginx&usg=ALkJrhhBlCzMe5ZczlhFCsU0cBOHIWcXIwhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1694450/why-dont-i-pass-any-parameters-to-a-function-within-map&usg=ALkJrhhgZJ3kuTQSOJ5DOYVCZWwKxObT7AProperties related to Spark deployment in spark gas - javaTwo declared constructors in the inner class - javaReplace the string with the matching pattern using sed - linuxAll Articles