Reputation: 266
I am currently developing an android game using LibGdx. I am trying to get the multi touch functionality working as the game requires the player to have one thumb to control the character and the other to click buttons.
Code:
for (int i = 0; i < 2; i++) {
if (Gdx.input.isTouched(i)) {
final int iX = Gdx.input.getX(i);
if (iX > screenwidth - screenwidth / 14) {
buttontouch = true;
} else {
buttontouch = false;
}
if (iX <= screenwidth - screenwidth / 14) {
playertouch = true;
}else{
playertouch = false;
}
}
}
if (playertouch){
etc...
}
if(buttontouch){
etc...
}
The player can be moved and the buttons pressed, but not at the same time :( ... which is what i need.
Any help would be greatly appreciated! Thanks in advance.
Upvotes: 1
Views: 369
Reputation: 266
Ok I seemed to have worked out an answer. added
if (Gdx.input.isTouched(i)) {
below in each boolean if
for (int i = 0; i < 2; i++) {
if (Gdx.input.isTouched(i)){
final int iX = Gdx.input.getX(i);
if (iX > screenwidth - screenwidth / 14) {
buttontouch = true;
} else {
buttontouch = false;
}
if (iX <= screenwidth - screenwidth / 14) {
playertouch = true;
}else{
playertouch = false;
}
}
}
//Logic here!
if (playertouch){
if (Gdx.input.isTouched(i)) {
etc...
}
}
if(buttontouch){
if (Gdx.input.isTouched(i)) {
etc...
}
}
}
Upvotes: 1
Reputation: 2155
Logic which moves your character should be called inside for
circle. You should move your character every circle iteration (if button was clicked) Like this:
for (int i = 0; i < 2; i++) {
if (Gdx.input.isTouched(i)) {
final int iX = Gdx.input.getX(i);
if (iX > screenwidth - screenwidth / 14) {
buttontouch = true;
} else {
buttontouch = false;
}
if (iX <= screenwidth - screenwidth / 14) {
playertouch = true;
}else{
playertouch = false;
}
}
//Logic here!
if (playertouch){
etc...
}
if(buttontouch){
etc...
}
}
Upvotes: 2