0

So , I am testing out a game with a simple ball (which is basically an object of UIImageView) fixed on the screen using CGPointMake and I am implementing a simple swipe gesture with UIGestureRecognizerDelegate.

My intention is to just flick the ball in a direction and I want the ball to move in that direction (flawlessly- which means the movement has to be really smooth), and it will depend on the direction and speed of the swipe.

I can understand that I can work with UISwipeGestureRecognizer and UIPanGestureRecognizer and find out the velocity of the swipe and fix the ball again with CGPointMake.

But, is there a really good way to obtain a really smooth movement on the ball with a particular velocity and direction ?

Legolas
  • 12,145
  • 12
  • 79
  • 132
  • AFAIK the UIPanGestureRecognizer is the way to go as the swipe-one will be invoking the preset selector when done only. So only the pan-gesture gives you a chance to actually let the ball follow the finger movement while still touching the screen. – Till Dec 24 '11 at 13:41
  • I want the ball to follow the trajectory after the swipe is initiated... may be 1 second after the swipe. `UIPanGestureRecognizer` actually moves the ball along with the swipe. – Legolas Dec 25 '11 at 00:16

1 Answers1

1

If i was you I'd try the normal touchesBegan:withEvent: methods that every UIView implements. Then you can always set the new frame until the touches end. Then you can calculate the direction and speed to continue moving it using an animation.

lbrndnr
  • 3,361
  • 2
  • 24
  • 34
  • and I'd would overwrite the same methods of a GestureRecognizer, as it also has this methods. Than you can assign the recognizer to any view — without subclassing into a new view. – vikingosegundo Dec 24 '11 at 16:08
  • Direction , yes, I can use some math to calculate it. How can you calculate the speed with `touchesBegan` and `touchesEnd` ? – Legolas Dec 25 '11 at 00:14
  • You could calculate the velocity using the coordinates of the touch in touchesMoved: and the time between the calls. – lbrndnr Dec 25 '11 at 04:59