Hello everyone. I was wondering if anyone could help with a question I have. I'm trying to simulate a "toss" when someone touches the ball and the flicks it. Could anyone suggest on how I use the flick gesture to simulate the toss? Basically use the flick for the speed of the throw. Any suggestions would be appreciated.
You should be able to use the touchesBegan and touchesEnded methods so long as your ball class inherits from UIResponder, which it should if it inherits from UIView or UIImageView.
In touchesBegan set an instance variable to the time the touch occurred and another to the location of the touch.
In touchesEnded set another use those instance variables to calculate how long the flick motion took and the distance of the flick and voila you have all the necessary components to calculate speed!
Thanks. Yea I started thinking about that. I do have it setup the way you described. I will just need to add the instance variables to keep track of the information.
You should be able to use the touchesBegan and touchesEnded methods so long as your ball class inherits from UIResponder, which it should if it inherits from UIView or UIImageView.
In touchesBegan set an instance variable to the time the touch occurred and another to the location of the touch.
In touchesEnded set another use those instance variables to calculate how long the flick motion took and the distance of the flick and voila you have all the necessary components to calculate speed!
Ok, when doing this I noticed that the timestamp that the touch object gives is the last time the touch was moved or when it was started. So like if you move it and hold it still for like 3 seconds, it doesn't register the 3 seconds that it was held. Would I need to keep track of the actual time instead of the time interval?
Would it be better to use touchesMoved rather than touchesEnded? Then the ball would move immediately after "throwing", not after the player lifts his finger.
Ok, when doing this I noticed that the timestamp that the touch object gives is the last time the touch was moved or when it was started. So like if you move it and hold it still for like 3 seconds, it doesn't register the 3 seconds that it was held. Would I need to keep track of the actual time instead of the time interval?
Why don't you just use a fixed time interval and measure the distance at the touches ended from the touches ended touch to the touch just prior? Use that distance to determine the speed of the flick.