How to awake screen while game play in libgdx?

南笙酒味 提交于 2020-02-28 13:38:07

问题


I am creating an game using accelerometer in libgdx and while playing the game, it sleeps after some, i need awake this untill game-play. i got this in some forums

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

which work for android app,but don't how to do that in libgdx, it is unrecognizable by compiler.any help will be appreciated.


回答1:


Best and easiest way to do that is

  1. Go to the android folder of your project in android studio

  2. then locate AndroidLauncher.java in src sub-folder

  3. then copy and paste code below

    @Override protected void createWakeLock(boolean use) { use=true; super.createWakeLock(use); }

    after adding code whole file will look like this

    public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); initialize(new MyBomber(), config);

    }

    @Override protected void createWakeLock(boolean use) { use=true; super.createWakeLock(use); } }




回答2:


onCreate method of AndoridLauncher create a configuration object and set useWakelock=true

AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useWakelock=true;

initialize(new MyGdxGame(), config);


来源:https://stackoverflow.com/questions/40160469/how-to-awake-screen-while-game-play-in-libgdx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!