-2

Strange one, but I want to do the following:

  • Have a round element about the size of a finger tip in the bottom right of the screen.
  • Have some images come in from the left of the screen, at the same Y position, which move from left to right and eventually overlap the above element.
  • Detect when that first element is touched, AND if an image element is overlapping it.

It's similar to how Dance Dance Revolution, or Guitar Hero works. They line up, you tap at the right time, and something happens.

I know how to set an onClickListener, but does anyone know how to achieve the above?

Cheers, Lee.

Lee Valentine
  • 95
  • 1
  • 2
  • 8
  • I'm thinking just an if statement, to detect if both elements were clicked at once. That would require all elements on the Z axis of a particular coordinate to be detected as clicked at once. Does anyone know if this is the default functionality? – Lee Valentine Oct 11 '15 at 06:07
  • Any reason for the negative points? Feelsliketroll.exe. – Lee Valentine Oct 11 '15 at 08:37

1 Answers1

0

So despite receiving down votes (would have been nice to let me know why, so I can avoid whatever it was in the future!), I'm going to post the solution which I eventually worked out on my own. Hopefully this will help someone else one day.

Note: I changed it a little. I now have ki blasts coming from the right of the screen, which move left, and when an image of Goku is tapped, the code checks if any of the ki blasts are at Goku's X-position, plus or minus 100 (so a 100px radius from Goku's center).

    // Set the touch listener for the image I want as the target
imgCurrentForm.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {

                    // Ki Blast image
                    ImageView kiBlast1 = (ImageView) findViewById(R.id.kiBlast1);

                    // Current X positions at any point in time
                    float xposForm = imgCurrentForm.getX();
                    float xposKi1 = kiBlast1.getX();

                    // Handle the screen touch event
                    int action = event.getAction();
                    switch (action) {

                        case MotionEvent.ACTION_DOWN:

                            if (currentPowerLevel >= 1 && currentPowerLevel <= 299999) {

                                if (Math.abs(xposForm - xposKi1) <= 100) {
                                    // Do whatever needs to be done if true
                                } 
                            }
                            break;
                    }
                    return true;
                }
            });
Lee Valentine
  • 95
  • 1
  • 2
  • 8
  • Its over 9000! It may be better to move this to an "Engine"/Policy class that does all the internal processing. Passing in the objects it needs to make decisions. Just a thought. – JoxTraex Oct 13 '15 at 02:39
  • Hi @JoxTraex, thanks for the suggestion. I'm new to Java but I'll do some research on that one, as I'm sure my code needs some serious refactoring! – Lee Valentine Oct 13 '15 at 06:55