Hello picking on android

try execute shoot method from laucher

        final Button shoot = findViewById(R.id.shoot);
        shoot.setText("Shoot");

        shoot.setOnTouchListener((view, event) -> {
             final boolean[] isShoot = new boolean[] { false };
             if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    isShoot[0] = true;
              } else if (event.getAction() == MotionEvent.ACTION_UP) {
                   isShoot[0] = false;
              }
           /* a callback to the application update */
           game.enqueue(() -> game.shoot());
           return true;
        });

not work

Okay, please test this instead:

final boolean[] isShoot = new boolean[] { false };
isShoot[0] = true;
/* a callback to the application update */
game.enqueue(() -> game.isShoot = isShoot[0]);
return true;

And then test this to see how the MotionEvents get triggered:

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    Toast.makeText(getApplicationContext(), "Down", Toast.LENGTH_SHORT).show();
              } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    Toast.makeText(getApplicationContext(), "Up", Toast.LENGTH_SHORT).show();
              }

Also, if you are triggering this from update, you need to reset the isShoot to false, like this:

 if(isShoot){
     shoot();
     isShoot = false;
 }

EDIT:
Also adding a print or a logging statement will help to diagnose the problem:

 if(isShoot){
     shoot();
     Logger.getLogger("DEBUG-SHOOTER").info("Shooting");
     isShoot = false;
 }
1 Like

tried it didn’t find any bugs
ray is not created correctly

How do you know? Did you log it? Or are you guessing because the final thing that should happen isn’t happening?