libgdx退出对话框
- package com.fxb.newtest;
- import com.badlogic.gdx.ApplicationListener;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.InputAdapter;
- import com.badlogic.gdx.InputMultiplexer;
- import com.badlogic.gdx.Input.Keys;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL10;
- import com.badlogic.gdx.graphics.Pixmap;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.Pixmap.Format;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.scenes.scene2d.Actor;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle;
- import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
- import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
- import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
- import com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle;
- import com.badlogic.gdx.scenes.scene2d.utils.Align;
- import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
- public class Lib005_CancelKey extends InputAdapter implements ApplicationListener{
- Stage stage;
- Skin skin;
- Dialog dialog1, dialog2;
- @Override
- public void create() {
- // TODO Auto-generated method stub
- CreateSkin();
- stage = new Stage();
- InputMultiplexer multiplexer = new InputMultiplexer();
- multiplexer.addProcessor( stage );
- multiplexer.addProcessor( this );
- Gdx.input.setInputProcessor( multiplexer );
- Gdx.input.setCatchBackKey( true );
- Gdx.input.setCatchMenuKey( true );
- TextButton textbutton1 = new TextButton( "Menu", skin );
- TextButton textbutton2 = new TextButton( "Exit", skin );
- textbutton1.addListener( new ChangeListener(){
- @Override
- public void changed(ChangeEvent event, Actor actor) {
- // TODO Auto-generated method stub
- dialog1.show(stage);
- }
- });
- textbutton2.addListener( new ChangeListener(){
- @Override
- public void changed(ChangeEvent event, Actor actor) {
- // TODO Auto-generated method stub
- dialog2.show(stage);
- }
- });
- textbutton1.setPosition( 100, 100 );
- textbutton2.setPosition( 200, 100 );
- stage.addActor( textbutton1 );
- stage.addActor( textbutton2 );
- }
- private void CreateSkin(){
- skin = new Skin();
- Pixmap pixmap = new Pixmap( 1, 1, Format.RGBA8888 );
- pixmap.setColor( Color.GRAY );
- pixmap.fill();
- //draw1 = new TextureRegionDrawable( );
- //texture = new Texture( pixmap );
- skin.add( "gray", new Texture(pixmap) );
- pixmap.setColor( Color.LIGHT_GRAY );
- pixmap.fill();
- skin.add( "light_gray", new Texture(pixmap) );
- BitmapFont font = new BitmapFont();
- WindowStyle windowStyle = new WindowStyle( font, Color.GREEN, skin.getDrawable( "light_gray" ) );
- LabelStyle labelStyle = new LabelStyle( font, Color.RED );
- ButtonStyle buttonStyle = new ButtonStyle( skin.getDrawable("gray"), skin.getDrawable("light_gray"), null );
- TextButtonStyle textbuttonStyle = new TextButtonStyle( skin.getDrawable("gray"), skin.getDrawable("light_gray"), null, font );
- skin.add( "default", buttonStyle );
- skin.add( "default", textbuttonStyle );
- skin.add( "default", windowStyle );
- skin.add( "default", labelStyle );
- dialog1 = new Dialog( "Menu", skin, "default" ){
- @Override
- protected void result(Object object) {
- // TODO Auto-generated method stub
- //System.out.println( "Chosen" + object );
- if( object.toString().equals( "true" ) ){
- System.out.println( "Yes" );
- Gdx.app.exit();
- }else{
- System.out.println( "No" );
- }
- }};
- dialog1.text("\nMenu").button("Yes", true).button("No",false).key(Keys.ENTER, true).key(Keys.ESCAPE,false);
- dialog1.setTitleAlignment( Align.top );
- dialog2 = new Dialog( "Exit", skin, "default" ){
- @Override
- protected void result(Object object) {
- // TODO Auto-generated method stub
- //System.out.println( "Chosen" + object );
- if( object.toString().equals( "true" ) ){
- System.out.println( "Yes" );
- Gdx.app.exit();
- }else{
- System.out.println( "No" );
- }
- }};
- dialog2.text("\nDo you want to exit?").button("Yes", true).button("No",false).key(Keys.ENTER, true).key(Keys.ESCAPE,false);
- dialog2.setTitleAlignment( Align.top );
- }
- @Override
- public void resize(int width, int height) {
- // TODO Auto-generated method stub
- }
- @Override
- public void render() {
- // TODO Auto-generated method stub
- Gdx.gl.glClearColor( 1, 1, 1, 1 );
- Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT );
- stage.act();
- stage.draw();
- }
- @Override
- public void pause() {
- // TODO Auto-generated method stub
- }
- @Override
- public void resume() {
- // TODO Auto-generated method stub
- }
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
- }
- @Override
- public boolean keyDown(int keycode) {
- // TODO Auto-generated method stub
- if( keycode == Input.Keys.BACK ){
- Gdx.app.log( "back", "" );
- dialog2.show(stage);
- }
- if( keycode == Input.Keys.MENU ){
- Gdx.app.log( "menu", "" );
- dialog1.show(stage);
- }
- return false;
- }
- }
libgdx开发中返回键(cancel)和菜单键(menu)的使用。
开始时需要设置Gdx.input.enableCancelKey或者Gdx.input.enableMenuKey,然后捕获到相应事件时添加事件响应即可。
libgdx退出对话框的更多相关文章
- Android 如何监听返回键,弹出一个退出对话框
android 如何监听返回键点击事件,并创建一个退出对话框, 防止自己写的应用程序不小心点击退出键而直接退出.自己记录下这个简单的demo,备用. public class BackKeyTest ...
- Android实现“是否退出”对话框和“带图标的列表”对话框
今天我们学习的内容是实现两种对话框(Dialog),第一种是询问是否退出对话框,另外一种是带图标的列表对话框,程序的执行效果是,我们点击button1的时候,弹出第一种对话框,我们点击button2的 ...
- [转]Android 如何监听返回键,弹出一个退出对话框
本文转自:http://blog.csdn.net/sunnyfans/article/details/8094349 Android 如何监听返回键点击事件,并创建一个退出对话框, 防止自己写的应用 ...
- Android 自定义AlertDialog退出对话框
Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...
- quick-cocos2d-x android返回键监听并实现原生退出对话框
这两天最终闲了一下,就顺手又把quick捡起来又学了学,一直都认为quick比cocos2dx那套lua绑定要方便很多,今天试了下android返回键的监听,还是挺好弄的,所以就有了这篇. 首先说明一 ...
- VB.Net中确认退出对话框的实现
实现方法分为两大类:窗体事件和控件事件,下面就一一展示: 一.FormClosing事件(又分以下几种方法) a. Private Sub frmPractise_FormClosing(ByVal ...
- MFC 关于new出一个新对话框时,退出对话框内存泄漏的问题解决
问题: 在进行点击按钮弹出对话框时,我是用了new来生成一个新的对话框,但是在新对话框关闭的时候,经过检查发现,新对话框存在内存泄漏问题. 原因: 因为使用了new,但是当时没有找到地方进行delet ...
- 在Android中自定义捕获Application全局异常,可以替换掉系统的强制退出对话框(很有参考价值与实用价值)
转载自: http://blog.csdn.net/jdsjlzx/article/details/7606423
- android studio中退出时弹出对话框
在app中总是不小心点击了退出怎么办?当然是加个弹出的提示框了,本人新手,就加在主界面上了 @Override public boolean onKeyDown(int keyCode, KeyEve ...
随机推荐
- Docker相关概念
一.概念 ①云计算:是一种资源的服务模式,该模式可以实现随时随地,便捷按需地从可配置计算资源共享池中获取所需的资源(如网络.服务器.存储.应用及服务),资源能够快速供应并释放,大大减少了资源管理工作的 ...
- SqlServer为字段创建索引
语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名) 创建索引实例: 聚簇索引 create clustered index index_name on table_name (c ...
- docker部署nginx,并实现负载均衡。
安装与使用 安装 nginx官网下载地址 发布版本分为 Linux 和 windows 版本. 也可以下载源码,编译后运行. 从源代码编译 Nginx 把源码解压缩之后,在终端里运行如下命令: $ . ...
- 关联与下钻:快速定位MySQL性能瓶颈的制胜手段
本文根据DBAplus社群[2018年1月6日北京开源与架构技术沙龙]现场演讲内容整理而成. 讲师介绍 李季鹏 新炬网络数据库专家 专注于MySQL数据库性能管理及相关解决方案,目前主要从事MySQL ...
- IP解析计算机名称
#-*- coding: UTF-8 -*- import subprocess,sys,threading reload(sys) sys.setdefaultencoding('utf-8') d ...
- LUA 运算笔记
循环 比如要实现这样的一个For for(int i=10;i>1;i—) { print(i) } lua的for循环 转换成LUA for i=10,1,-1 do print(i) end ...
- kettle性能优化
普通开发电脑,如果没有网络查询步骤,kettle正常的速度应该在3000~20000条/秒.如果速度在2000条/秒一下,就可能需要调优. 性能优化的方式包括如下几种: 1.通过改变开始复制的数量(针 ...
- 参观阿拉斯加进行产品培训[My representation]
I suggest to visit Alaska for product training. Alaska is one of the best places to spend a trainin ...
- 028、HTML 标签3表单标签插入组件
内容:表单标签插入组件(经常使用)############################################################## form表单标签和input组件 < ...
- istio1.0.2配置
项目的组件相对比较复杂,原有的一些选项是靠 ConfigMap 以及 istioctl 分别调整的,现在通过重新设计的Helm Chart,安装选项用values.yml或者 helm 命令行的方式来 ...