How to verify if the user draw a line over a collection of points in cocos2d
I am doing alphabet tracing application for kids. I have given the dotten points. how to identify that am moving over that points. using Touches moved, i want to write.If moved incorrectly, i don开发者_C百科t like to draw lines. plz share ur ideas
The simple version is:
- Record the initial touch-point on
touchesBegan
. - On each
touchesMoved
call, do:- Interpolate a reasonable number of points (a dozen or so should be sufficient) between the initial touch-point and the current touch-point.
- For each interpolated point, perform a hit-test against your "dot" locations. This can be done by computing the linear distance between the point and the "dot" location, and counting any distances closer than some threshold as a "hit".
- Set the initial touch-point to the current touch-point.
- On
touchesEnded
, perform one final round of interpolation and hit-test, and then clear your initial touch-point.
Of course you may want to add some extensions of your own to the basic algorithm, such as keeping an array of all the contacted points to check at the end of the event to help discriminate coordinated interactions from random nonsense, and so on.
精彩评论