When I use the method onTouch, I use the methon event.getY() to give the variable y2 the finger precision. But one problem apper when I use a if-statement:
public boolean onTouch(View v, MotionEvent event){
if(y2 <= knifeY){
//y2 = where the finger is, knifeY = where on the height a knife will be on.
knifeDown = false;
// The knife stops
point--;
// score - 1;
knife = BitmapFactory.decodeResource(getResources(),R.drawable.bloddyknife);
// change picture.
return true;
}
}
But the problem is that you must move your finger when you hold it on the screen, if you’re holding it still, the knife just slip past. 🙁
Someone help?
Do you assign
int y2=event.getY()? Because I dont see it anywhere, it must be done inside theonTouch()I’m not sure if this is good approach
I suggest you to use
GestureListenerand useonFling()for this purpose.Read here more on constants of
MotionEventclass:http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN