iphone - XCode - touchBegan - Recent Touches/New Touches -
i have been using touches began track many 8 touches, , each triggers event. these touches can occur @ same time, or staggered.
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { nslog(@"touch began"); nsset *alltouches = [event alltouches]; (int i=0; i<alltouches.count; i++) { uitouch *touch = [[alltouches allobjects] objectatindex:i]; if (/*touch inside button in question*/) { //trigger event. } } }
that code works multitouch, , has no problems, except: (see if can guess)
due way alltouches works, literally gets of touches. because of this, loops through of touches active when user starts touch, , triggers event of 1 of buttons twice.
ex: johnny pressing button 1. event 1 occurs. johnny leaves finger on button 1, , presses button 2. event 2 occurs, button 1 still part of alltouches, , so, event 1 triggered again.
so here's question: how new touch?
the same touch object returned on subsequent calls touchesbegan continuous touch. save each uitouch *touch have handled begun (and not yet ended), , iterate next time in touchesbegan, skip ones you've saved/marked.
Comments
Post a Comment