libgdx-机器人:拦截返回键和确认退出 [英] libgdx-android: Intercepting back key and confirm exit

查看:306
本文介绍了libgdx-机器人:拦截返回键和确认退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用libgdx,我怎么能拦截安卓BACK键,以便做一些preprocessing(如要求确认来自用户),在实际执行命令,退出游戏?

Using libgdx, how can I intercept the android BACK key in order to do some preprocessing (e.g. asking for confirmation from user), before actually performing the command to exit the game?

推荐答案

1。启用捕获返回键的。

在类实现了ApplicationListener

   @Override
   public void create() {
        ...
        Gdx.input.setCatchBackKey(true);
        ...
   }

2。处理醒目返回键的。

在实现 InputProcessor ​​

   @Override
   public boolean keyDown(int keycode) {
        ...
        if(keycode == Keys.BACK){
           // Optional back button handling (e.g. ask for confirmation)
           ...
           if (shouldReallyQuit)
             Gdx.app.exit();
        }
        return false;
   }

这篇关于libgdx-机器人:拦截返回键和确认退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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