Reputation: 882
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?
Upvotes: 0
Views: 90
Reputation: 50538
Do you assign int y2=event.getY()
? Because I dont see it anywhere, it must be done inside the onTouch()
I'm not sure if this is good approach
public boolean onTouch(View v, MotionEvent event)
{
while(event.getAction()!=MotionEvent.ACTION_CANCEL) // or here measure the pressure applied on the screen surface
{
if(event.getY() <= knifeY)
{
knifeDOwn=false; // keep the knife down
point--;
knife = BitmapFactory.decodeResource(getResources(),R.drawable.bloddyknife); //
//maybe here you might stop the pointers collecting with using event.setAction(MotionEvent.ACTION_CANCEL) (or ACTION_UP) to exit the while loop, i dont know your idea for it, at this point i'm just guessing, but you still need to change the action of the event at anypoint at this code to exit the while loop.
}
}
return true;
}
I suggest you to use GestureListener
and use onFling()
for this purpose.
Read here more on constants of MotionEvent
class:
http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN
Upvotes: 1