Detect that SKShapedNode is closed

佐手、 提交于 2019-12-12 03:07:42

问题


In my future game(in SpriteKit), I need to draw circle-like shapes. I use CGMutablePathRef and SKShapeNode for drawing itself.

On touchesEnded I need to check if the user did close the circle or if there is a gap between start and end touches. (Strictly saying, it can be not only the right circle, I need to detect any closed shape, e.g. loop...)

How can I do this checking?


回答1:


  1. Store the touches locations (points) in an array: [yourArray addObject:[NSValue valueWithCGPoint:yourPoint]];
  2. Make a rect (size? your choice! the smaller it is, the more precise) around the first point in the array (first touch location).
  3. Control if the rect also contains the last point in the array (last touch location).
  4. If so, then close your path.


来源:https://stackoverflow.com/questions/29366828/detect-that-skshapednode-is-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!