Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bouncing ball app in touch listener in android

I refer this link Bouncing Ball.When user touch on ball, it stops moving & When user release ball then it continues moving. how can we do it using touch gesture ?

Thank you in Advance.

like image 384
Jigar Shekh Avatar asked Dec 28 '25 20:12

Jigar Shekh


1 Answers

As i said earlier that is much declarative answer to help you here.You need to share your code here to help something.

I would like to give you some hint to do this: override onTouchEvent(MotionEvent event) method. Use event.getAction() to catch various MotionEvent. When you can identify MotionEvent.ACTION_DOWN then set event.getX() and getY() as your objects current x,y. That will stop moving your object.

Similarly, at MotionEvent.ACTION_UP update your objects position(x,y according to the direction), and set yourObject.setTouched(false). So when user release his finger from the screen object will start to move again.

like image 143
ridoy Avatar answered Dec 31 '25 08:12

ridoy