简体   繁体   English

如何使用libgdx获取Touch Event TouchUp

[英]How to get Touch Event TouchUp using libgdx

Am trying to change the screen when removes his finger/ no longer touches the screen Have tried doing it this way 试图在移开手指/ 不再触摸 屏幕更换屏幕

if (Gdx.input.isTouched(0)) {
camera.unproject(_touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
//stuff...
}

Now When ever the User leaves his finger i want to change the Screen Have also tried to use this call 现在,当用户离开手指时,我想更改屏幕也尝试使用此呼叫

Gdx.input.setInputProcessor(processor);

But of no idea how to check/use this event in render method . 但是不知道如何在render方法中检查/使用此事件 Please help me out on this. 请帮助我。

使您的类实现InputProcessor并调用Gdx.input.setInputProcessor(this);

You can detect touchUp events just overriding the proper method from a Screen subclass.- 您可以检测到touchUp事件,而只是重写Screen子类中的适当方法即可。-

@Override
public boolean touchUp(int x, int y, int pointer, int button) {         
    boolean res = super.touchUp(x, y, pointer, button);

    // Do your stuff here

    return res;
}

When you use 使用时

Gdx.input.setInputProcessor(processor);

you don't have to call any function in your render method. 您无需在render方法中调用任何函数。 Libgdx will directly give you a call back in your processor about the various events. Libgdx会直接在处理器中给您回覆各种事件。 you just need to write the code to change the screen in touch up function of your processor (InputProcessor). 您只需要编写代码即可更改处理器(InputProcessor)的触摸屏功能中的屏幕。 use this link to get more clarification https://code.google.com/p/libgdx/wiki/InputEvent 使用此链接获得更多说明https://code.google.com/p/libgdx/wiki/InputEvent

布尔值isTouched = Gdx.input.isTouched();

只需使用Gdx.input.justTouched()而不是isTouched()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM