开发者

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

How to verify if the user draw a line over a collection of points in cocos2d


The simple version is:

  1. Record the initial touch-point on touchesBegan.
  2. On each touchesMoved call, do:
    1. Interpolate a reasonable number of points (a dozen or so should be sufficient) between the initial touch-point and the current touch-point.
    2. 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".
    3. Set the initial touch-point to the current touch-point.
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜