Reputation: 1270
I am working on a simple game. While user is touching the screen, increment some variable. While not, do nothing. I am Using surfaceView onTouchEvent, but it doesn't work because it is called only once. How can I accomplish such functionality?
@Override
public boolean onTouchEvent(MotionEvent event) {
vehicle.vel_y -=0.2f;
return super.onTouchEvent(event);
}
Upvotes: 2
Views: 435
Reputation: 7985
Read about the MotionEvents that are passed to the onTouchEvent method. Specifically, look at ACTION_DOWN
and ACTION_UP
. You should receive motion events when a pointer touches the screen and when it leaves the screen.
Beyond that, the fun part is figuring out how to record progress between the ACTION_DOWN
and ACTION_UP
events (=
If you need a hint, you might start by looking at:
Upvotes: 2
Reputation: 934
In your XML layout file, you should set longClickable property of SurfaceView to true
android:longClickable="true"
Upvotes: 0