如何在 libgdx 中玩游戏时唤醒屏幕? [英] How to awake screen while game play in libgdx?
问题描述
我正在使用 libgdx 中的加速度计创建一个游戏,在玩游戏时,它会在一段时间后休眠,我需要在玩游戏之前将其唤醒.我在一些论坛上得到了这个
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);
适用于 android 应用程序,但不知道如何在 libgdx 中执行此操作,编译器无法识别它.任何帮助将不胜感激.
which work for android app,but don't how to do that in libgdx, it is unrecognizable by compiler.any help will be appreciated.
推荐答案
最好和最简单的方法是
在android studio中进入你项目的android文件夹
Go to the android folder of your project in android studio
然后在 src 子文件夹中找到 AndroidLauncher.java
then locate AndroidLauncher.java in src sub-folder
然后复制粘贴下面的代码
then copy and paste code below
@Override protected void createWakeLock(boolean use) { use=true;super.createWakeLock(使用);}
@Override protected void createWakeLock(boolean use) { use=true; super.createWakeLock(use); }
添加代码后整个文件将如下所示
after adding code whole file will look like this
公共类 AndroidLauncher 扩展 AndroidApplication { @Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate(savedInstanceState);AndroidApplicationConfiguration 配置 = 新AndroidApplicationConfiguration();初始化(新的我的轰炸机(),配置);
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(使用);} }
@Override protected void createWakeLock(boolean use) { use=true; super.createWakeLock(use); } }
这篇关于如何在 libgdx 中玩游戏时唤醒屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!