2

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);
}
Joe
  • 1,270
  • 2
  • 17
  • 24

2 Answers2

2

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:

repeating events using handlers

Community
  • 1
  • 1
dcow
  • 7,765
  • 3
  • 45
  • 65
  • This helped me I just set one bool variable in ACTION_DOWN/UP and in separate thread is used this variable for setting the condtition. Thanks – Joe Nov 14 '12 at 11:51
0

In your XML layout file, you should set longClickable property of SurfaceView to true

android:longClickable="true"