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 AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
