How to detect when an actor is touched in libgdx?(如何在 libgdx 中检测演员何时被触摸?)
问题描述
我在我的 Screen 方法的 render 方法中使用Gdx.input.isTouched()",以了解触摸的位置,但是当在屏幕中拖动触摸时,它也会激活我想要的事件,仅当演员被感动了.
I am using "Gdx.input.isTouched()" in the render method of my Screen method, to know where is touched, but when the touch is dragged in the screen, it also activates the events i want only when an actor is touched.
是否有任何监听器知道何时触摸了 Actor,但事件不是被拖动的事件,我是用精灵做的.
Is there any listener to know when an Actor is touched, but the event is not the dragged one, im doing it with sprites.
推荐答案
查看这个关于 的 wiki 页面LibGDX 中的场景 2d.特别是关于输入处理的部分.
See this wiki page about scene2d in LibGDX. Specifically the part about Input handling.
基本上你必须在你的 Actor 中重写这些方法中的一个或多个:
Basically you have to override one or more of these methods in your Actor:
public boolean touchDown (float x, float y, int pointer) {
return false;
}
public void touchUp (float x, float y, int pointer) {
}
public void touchDragged (float x, float y, int pointer) {
}
public boolean touchMoved (float x, float y) {
return false;
}
public boolean scrolled (int amount) {
return false;
}
public boolean keyDown (int keycode) {
return false;
}
public boolean keyUp (int keycode) {
return false;
}
public boolean keyTyped (char character) {
return false;
}
这篇关于如何在 libgdx 中检测演员何时被触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 libgdx 中检测演员何时被触摸?


基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01