如何在 libgdx 中检测演员何时被触摸?

How to detect when an actor is touched in libgdx?(如何在 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 中检测演员何时被触摸?

基础教程推荐