On the bottom left of my screen is a circle with an Arrow and on the bottom right is a circle with a gun. If the player is in jetpack mode and the Arrow "button" is clicked he flies like flappy bird (touch down = push him upwards, touch up = he falls down) - if the player is in jump mode he simply jumps.
My problem is I can't seem to fly the jetpack upwards AND shoot a bullet at the same time (i.e. the case where I'm tapping both the Arrow and the Gun). Is there some sort of trick I can use here?
My touchDown() method is in a class Controller looks like this:
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
int tapY = Gdx.graphics.getHeight() - screenY;
//true if the arrow (bottom left) is tapped
arrowClicked = inRange(upArrowSprite, screenX, tapY);
//true if the gun (bottom right) is tapped
gunClicked = inRange(gunSprite, screenX, tapY);
// if arrow is pressed and player isn't in jetpack mode, make him jump
if (arrowClicked) {
if (!(player.getState() == ObjectState.JETPACK_MODE)) {
player.setState(ObjectState.JUMPING);
player.jump();
// if the player is in jetpack mode, accelerate him upwards every time arrow is tapped
} else {
player.setTouchedDownFlying(true); // set boolean to be true
player.setState(ObjectState.JETPACK_MODE);
}
}
//if the gun is tapped (bot right), shoot a bullet
if (gunClicked) {
player.shoot();
}
return true;
}
these are the relevant methods in Player:
public void update() {
moveBy(xSpeed, -gravity);
...
if(touchedDownFlying) {
jetPackFly();
}
...
}
public void setTouchedDownFlying(boolean bool) {
touchedDownFlying = bool;
}
public void jetpackFly() {
setySpeed(getySpeed() + flyAcceleration);
}
public void shoot() {
Bullet i = new Bullet(this);
bullets.add(i);
}
Any help is highly appreciated, thank you :)