处理libgdx中的多点触控

bre*_*hts 8 java android multi-touch libgdx

好吧所以我一直在尝试为我的libgdx游戏实现多点触控解决方案并遇到一些麻烦.基本上,我在控制我的性格,并在屏幕的remaing部分要处理刷卡才能有人物跳跃,打孔或者在敌人扔东西方向在屏幕的左下方象限DPAD.我最初考虑过在GestureListener中使用fling但是我已经被告知多点触控不支持fling并且从那时起开始使用pan来检测滑动.我目前遇到的问题是,如果我在屏幕上用手指在使用刷卡(玩家移动,并试图跳),通过平移停止指针似乎是对我的记录和理解不正确的(至少巴斯(无论如何)这里的代码是下面的代码和手势检测器上文档的链接,如果有人可以帮助解释发生了什么将非常感激.

@Override
public boolean touchDown(float x, float y, int pointer, int button) {
    if (x < width / 3 && y > height / 2) {
        directionPointer= pointer;
        if(x< width/6){     
            controller.leftPressed();
            message=" driection TOUCH DOWN POINTER IS: " + pointer  + "the action pointer -> " +actionPointer +"directionPointer->"+ directionPointer;
            Gdx.app.log("INFO", message);   
        return true;
    }else{oller.rightPressed(); 
        message=" direction TOUCH DOWN POINTER IS: " + pointer  + "the action pointer -> " +actionPointer +"directionPointer->"+ directionPointer;
        Gdx.app.log("INFO", message);   
        return true;

    }       

}else{
    actionPointer= pointer;
    down_x=x;
    down_y=y;
    message= "Pointer value is" + actionPointer;
}

message="TOUCH DOWN POINTER IS: " + pointer  + "the action pointer -> " +actionPointer +"directionPointer->"+ directionPointer;
Gdx.app.log("INFO", message);   
return false;
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {

    if ( pointer == directionPointer) {         
        controller.leftReleased();
        controller.rightReleased(); 
        directionPointer=-1;
        return true;                
    }
    if (x < width / 3 && y > height / 2) {

        controller.leftReleased();
        controller.rightReleased(); 
        directionPointer=-1;
        message= "TOUCHUP pointer is ->"+ pointer + "actionPointer->"+ actionPointer + "directionPointer-> "+ directionPointer;
        Gdx.app.log("INFO", message);
            return true;                
    }

    message= "touchUP was detected";
    Gdx.app.log("INFO", message);
    return false;

}

@Override
public boolean panStop(float x, float y, int pointer, int button) {
    message="swipe not processed";
    if( pointer==actionPointer){
        delta_x= Math.abs(down_x -x);
        delta_y= Math.abs(down_y - y);
        if (delta_x < delta_y ){
            // this is an up or down value 
            if(down_x > x){
                controller.bobPunch();
                message = "SWIPE DOWNWARD " ;           
            }else {
                // swipe up 
                controller.bobJump();
                message = "SWIPE UPWARD " ;
            }           
        }else{
            if(down_y< y){
                controller.throwPressed();
                message=" SWIPE RIGHT";
                //swipe right ward 
            }else{
                controller.throwPressed();
                message=" SWIPE LEFT";
               // swipe left    
            }
        }
    }
    Gdx.app.log("INFO", message);
    message="panstop pointer is : " + pointer  + "the action pointer-> " +actionPointer + "directionPointer->" + directionPointer;
    Gdx.app.log("INFO", message);
    actionPointer=-1;
    // TODO Auto-generated method stub
    return true;
}
Run Code Online (Sandbox Code Playgroud)

现在这是检测应该采取什么操作的相关代码(directionPointer和actionPointer是全局整数初始化广告-1)问题是panStop返回的指针不是我预期的,这里有一些输出日志文件用于不同的触摸操作来显示什么正在发生 :

案例1:按住屏幕的左下角(bob向左移动):

direction TOUCHdOWN POINTER IS: 0 action pointer->-1 directionpointer->0
Run Code Online (Sandbox Code Playgroud)

case2向上滑动(bob jumps)

TOUCHdOWN POINTER IS: 0 action pointer->0 directionpointer->-1
SWIPE UPWARD
panstop pointer is: 0 actionpointer->0 directionpointer->-1
Run Code Online (Sandbox Code Playgroud)

案例3移动和跳转(这里是问题所在):

direction TOUCHdOWN POINTER IS: 0 action pointer->-1 directionpointer->0
TOUCHdOWN POINTER IS: 1 action pointer->1 directionpointer->0
swipe not processed
panstop pointer is: 0 actionpointer->1 directionpointer->0
Run Code Online (Sandbox Code Playgroud)

现在最后一行虽然我无法向你证明这是问题,因为我平移的手指被注册为动作指针,方向指针(不离开屏幕)是返回的.任何人都可以指出我做错了或者这是libgdx本身的错误还是我的代码本身更有可能

`

小智 1

您实际上可以做的是让 DPAD 成为连接到舞台的 Actor,而屏幕控件由 InputProcessor 或 GestureListener 处理,并使用 InputMultiplexer 来组合它们:

InputMultiplexer im = new InputMultiplexer(stage, inputProcessor);
Gdx.input.setInputProcessor(im);
Run Code Online (Sandbox Code Playgroud)

另外,如果我没有记错的话,发送到 InputMultiplexer 的参数的顺序也被视为优先级。这意味着在上述情况下,舞台 (DPAD) 将优先于屏幕控件。因此,就您而言,您可能想要切换它们。

我知道这对您来说可能不是一个好的解决方案,但我在一些游戏中一直这样做。