How to detect when an actor is touched in libgdx?

不打扰是莪最后的温柔 提交于 2019-11-29 15:24:37
Ludevik

See this wiki page about scene2d in LibGDX. Specifically the part about Input handling.

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;
}
ManhPhi

in libGDX Actor have a listener inside. Example if you want check when a button is press, or is check, you call : button.isPressed(), button.isCheck(), it return boolean.

Siddharth

I think you have to implement one of the following method to detect only single time touch not the move event perform by the user.

Gdx.input.justTouched();

I think you control in Stage when you have multi-actors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!