Reputation: 129
I have a big problem with my 2 created buttons that can move.. They both work but are using the same getX(), get Y() data. How can i make them take differend data when i touch them with differend fingers at the same time?
(one button is for moving next is for shooting)
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;}
}
Upvotes: 0
Views: 157
Reputation: 13571
You should use
Gdx.Input.getX(int pointer)
and try to iterate from up to some max count of touches (in your example 2) to get all X and Y coordinates of fingers touching screen. Then just check if any of (x, y) is about one of your button.
Please consider also using Scene2d and its Actors and ContactListeners. I think it would be very very helpful here in your case.
You can read about it here:
https://github.com/libgdx/libgdx/wiki/Scene2d
Upvotes: 1