如何在 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 中检测演员何时被触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)