在libgdx中玩游戏时如何唤醒屏幕? [英] How to awake screen while game play in libgdx?

查看:66
本文介绍了在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.

推荐答案

最好,最简单的方法是

  1. 转到android studio中项目的android文件夹

  1. 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 {@Override 受保护的void onCreate(捆绑的saveInstanceState){ super.onCreate(savedInstanceState); AndroidApplicationConfiguration config =新 AndroidApplicationConfiguration();初始化(新的MyBomber(), config);

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆