gpt4 book ai didi

java - libgdx 中的多点触控

转载 作者:行者123 更新时间:2023-12-01 11:10:23 25 4
gpt4 key购买 nike

我创建的 2 个可以移动的按钮有一个大问题。它们都可以工作,但使用相同的 getX()、get Y() 数据。当我同时用不同的手指触摸它们时,如何使它们获取不同的数据?

(一个按钮用于移动,下一按钮用于拍摄)

foreverTimer+=delta;
if(foreverTimer<0.1){if(attackPressed){
float y=0, x=0, getY=Gdx.input.getY(), getX=Gdx.input.getX();
if((HEIGHT - getY)>=attackY+attackButton.getHeight()/3||(HEIGHT - getY)<=attackY-attackButton.getHeight()/3||getX>attackX+attackButton.getWidth()/3||getX<attackX-attackButton.getWidth()/3)
{
y=(HEIGHT - getY-attackY); x = getX-attackX;
Player.shoot(x, y);
}}
}else
if(foreverTimer>=0.1){
//RIGHT HERE I COMMAND TO TAKE NEW X,Y FOR NEXT BUTTON AND TURN OFF OTHER BUTTON BUT THE X AND Y ARE STILL THE SAME
float getY=Gdx.input.getY(), getX=Gdx.input.getX();
foreverTimer-=0.1;
if(movePressed)
{
if(getX>moveX+moveButton.getWidth()/3){a=false; d=true;} else if(getX<moveX-moveButton.getWidth()/3){d=false; a=true;} else{a=false; d=false;}
if((HEIGHT - getY)>moveY+moveButton.getHeight()/2){s=false; Player.sit=false; spres=false; w=true; wpres=true;} else if((HEIGHT - getY)<moveY-moveButton.getHeight()/2){s=true; spres=true; w=false; wpres=false;} else{s=false; Player.sit=false; spres=false; w=false; wpres=false; }
}else {wpres=spres=d=a=false;}
}

最佳答案

你应该使用

    Gdx.Input.getX(int pointer)

并尝试从最大触摸次数(在示例 2 中)进行迭代,以获得手指触摸屏幕的所有 XY 坐标。然后只需检查 (x, y) 是否与您的某个按钮有关。

请考虑同时使用Scene2d及其Actors和ContactListeners。我认为这对于您的情况非常有帮助。

您可以在这里阅读:

https://github.com/libgdx/libgdx/wiki/Scene2d

关于java - libgdx 中的多点触控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32446588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com