Strange one, but I want to do the following:
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.
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;
}
});