Is there any function in cocos2d or objective c to find the time between touch began and touch ended??
A:
In your touchesBegan:withEvent:
method, create an NSDate object and store it in an instance variable. (For non-debugging purposes, create one date per touch and use CFMutableDictionary to associate the date with the touch.) Then, in touchesEnded:withEvent:
, retrieve the stored date and create a new date, and send the latter a timeIntervalSinceDate:
message to subtract the older date from it, giving you the result in seconds.
Peter Hosey
2009-08-20 12:40:04
It's my understanding cocos2d takes care of implementing these methods and abstracts them away.
jbrennan
2009-08-20 18:00:49
+1
A:
Each UITouch has it's own time/date stamp. Compare the ones you're interested in. Take a looke at the UIResponder class ref.
Aside- SO needs to update their code or release an iPhone app. Typing into their javascriptoided out text fields with an iPhone is almost comical.
Meltemi
2009-08-20 17:34:57
+7
A:
// add this ivar to your view controller
NSTimeInterval lastTouch;
// assign the time interval in touchesBegan:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
{
lastTouch = [event timestamp];
}
// calculate and print interval in touchesEnded:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
{
NSTimeInterval touchBeginEndInterval = [event timestamp] - lastTouch;
NSLog(@"touchBeginEndInterval %f", touchBeginEndInterval);
}
willc2
2009-08-24 23:44:58