LibGdx 2 half screen quot;buttonsquot;(LibGdx 2 半屏“按钮)
问题描述
(Android)所以我是 LibGdx 的新手,我正在尝试编写这个 chrome dino 迷你游戏.我想在用户触摸屏幕左侧时执行操作 1,并在用户触摸屏幕左侧时执行操作 2触摸屏幕右侧,怎么办?
(Android) So I'm new to LibGdx and I'm trying to code this chrome dino mini game.. I want to make action 1 when the user touch the left hand side of the screen and make action 2 when he touch the right hand side of the screen, how can I do it?
推荐答案
您可以通过在游戏循环中的某处使用以下代码来检测被触摸的一侧:
You can detect the side being touched by using the following code somewhere inside your game loop:
if (Gdx.input.isTouched()) {
if (Gdx.input.getX() > Gdx.graphics.getWidth() / 2){
//touched right
} else {
//touchde left
}
}
这篇关于LibGdx 2 半屏“按钮"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LibGdx 2 半屏“按钮"


- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 转换 ldap 日期 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01