GestureDetector和InputListener在libgdx [英] GestureDetector and InputListener in libgdx

查看:490
本文介绍了GestureDetector和InputListener在libgdx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来libgdx和我想要在这里实现的是,我希望我的GestureDetector在同一时间InputListener工作。我有左边两个按钮,我需要他们继续即使我开始在同一时间(多点触控)刷卡反应。我用InputMultiplexer但它不工作方式我需要的。我检查,我需要返回true,也GestureInputListener是实现GestureDetector.GestureListener类InputListener和GestureDetector的所有返回值和一切。我只在它使用一扔。既GestureInputListener和InputListener工作,但不是在同一时间。你能帮助我吗?链接的想法。谢谢。低于code:

  inputMultiplexer.addProcessor(阶段);
inputMultiplexer.addProcessor(新GestureDetector(gestureInputListener));
Gdx.input.setInputProcessor(inputMultiplexer);


解决方案

然后,而不是使用输入多路复用器使用code为:

 公共类MyGestureDetector扩展GestureDetector {
    公共MyGestureDetector(GestureListener监听){
        超(监听);
    }    @覆盖
    公共布尔润色(浮法X,浮法Y,INT指针,INT按钮){
        super.touchUp(X,Y,指针,按钮);        //你的code这里
        返回true;
    }
}

同样的其他功能,如着陆等可以在这里添加不要忘记从函数调用super,因为这将使得各种功能像一扔,然后点击工作

编辑:

改实施

 公共类MyGestureDetector扩展GestureDetector {
    私人阶段阶段;
    公共MyGestureDetector(GestureListener监听器,舞台舞台){
        超(监听);
        this.stage =阶段;
    }
    @覆盖
    公共布尔KEYDOWN(INT键code){
        stage.keyDown(键code);
        super.keyDown(键code);
        返回false;
    }    @覆盖
    公共布尔KEYUP(INT键code){
        stage.keyUp(键code);
        super.keyUp(键code);
        // TODO自动生成方法存根
        返回false;
    }    @覆盖
    公共布尔的keyTyped(CHAR字符){
        // TODO自动生成方法存根
        stage.keyTyped(字符);
        super.keyTyped(字符);
        返回false;
    }    @覆盖
    公共布尔触地(INT screenX,诠释screenY,INT指针,INT按钮){
        stage.touchDown(screenX,screenY,指针,按钮);
        super.touchDown(screenX,screenY,指针,按钮);
        返回false;
    }    @覆盖
    公共布尔润色(INT screenX,诠释screenY,INT指针,INT按钮){
        stage.touchUp(screenX,screenY,指针,按钮);
        super.touchUp(screenX,screenY,指针,按钮);
        返回false;
    }    @覆盖
    公共布尔touchDragged(INT screenX,诠释screenY,诠释指针){
        // TODO自动生成方法存根
        stage.touchDragged(screenX,screenY,指针);
        super.touchDragged(screenX,screenY,指针);        返回false;
    }    @覆盖
    公共布尔的mouseMoved(INT screenX,诠释screenY){
        stage.mouseMoved(screenX,screenY);
        super.mouseMoved(screenX,screenY);
        返回false;
    }    @覆盖
    公共布尔滚动(INT量){
        stage.scrolled(量);
        super.scrolled(量);
        // TODO自动生成方法存根
        返回false;
    }
}

下面阶段是scene2d舞台上,并有可能是浮动的一些错误,或取决于你使用这个写在0.9.9 Nightlies版的libgdx版本参数诠释

P.S.-此实现定制按您的问题,但它应该尝试过每一种情况下被作为前

解释返回true或false来处理

I'm new to libgdx and what I'm trying to achieve here is that I want my GestureDetector to work at the same time with InputListener. I have two buttons on the left and I need them to keep reacting even if I start swiping at the same time(multitouch). I used InputMultiplexer but it doesn't work that way I need. I checked all the return values of InputListener and GestureDetector and everything that I need returns true, also GestureInputListener is a class that implements GestureDetector.GestureListener. I only used fling in it. Both GestureInputListener and InputListener work but not at the same time. Could you help me with that? links, ideas. Thanks. Code below:

inputMultiplexer.addProcessor(stage);
inputMultiplexer.addProcessor(new GestureDetector(gestureInputListener));
Gdx.input.setInputProcessor(inputMultiplexer); 

解决方案

then instead of using input multiplexer use code as:

public class MyGestureDetector extends GestureDetector {
    public MyGestureDetector(GestureListener listener) {
        super(listener);
    }

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

        // Your Code Here
        return true;
    }
}

similarly other functions such as touchdown etc can be added here don't forget to call super from functions as this will make various function like fling and tap work

Edit:

change the implementation to

public class MyGestureDetector extends GestureDetector {
    private Stage stage;
    public MyGestureDetector(GestureListener listener,Stage stage) {
        super(listener);
        this.stage = stage;
    }


    @Override
    public boolean keyDown(int keycode) {
        stage.keyDown(keycode);
        super.keyDown(keycode);
        return false;
    }

    @Override
    public boolean keyUp(int keycode) {
        stage.keyUp(keycode);
        super.keyUp(keycode);
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean keyTyped(char character) {
        // TODO Auto-generated method stub
        stage.keyTyped(character);
        super.keyTyped(character);
        return false;
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        stage.touchDown(screenX, screenY, pointer, button);
        super.touchDown(screenX, screenY, pointer, button);
        return false;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        stage.touchUp(screenX, screenY, pointer, button);
        super.touchUp(screenX, screenY, pointer, button);
        return false;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        // TODO Auto-generated method stub
        stage.touchDragged(screenX, screenY, pointer);
        super.touchDragged(screenX, screenY, pointer);

        return false;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        stage.mouseMoved(screenX, screenY);
        super.mouseMoved(screenX, screenY);
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        stage.scrolled(amount);
        super.scrolled(amount);
        // TODO Auto-generated method stub
        return false;
    }


}

Here stage is the scene2d Stage and there might be some error of float or int in parameters depending on the libgdx version you are using this is written in 0.9.9 nightlies

P.S.- This implementation is customised as per your problem but it should be tried that every case to be handled by returning true or false as explained before

这篇关于GestureDetector和InputListener在libgdx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆