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 半屏“按钮"


基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01