检测SKShapedNode已关闭 [英] Detect that SKShapedNode is closed
本文介绍了检测SKShapedNode已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在未来的游戏中(在SpriteKit中),我需要绘制圆形的形状。我使用 CGMutablePathRef
和 SKShapeNode
进行绘制。
In my future game(in SpriteKit), I need to draw circle-like shapes. I use CGMutablePathRef
and SKShapeNode
for drawing itself.
在 touchesEnded
上,我需要检查用户是否确实闭合了圆圈或开始和结束触摸之间是否存在间隙。
(严格地说,它不仅可以是正确的圆,还需要检测任何闭合的形状,例如环线...)
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...)
我该怎么办
推荐答案
- 将触摸位置(点)存储在数组中:
[yourArray addObject:[NSValue valueWithCGPoint:yourPoint]];
- 制作矩形(大小?您选择!越小越精确)围绕阵列中的第一点(第一触摸位置)。
- 控制rect是否还包含数组中的最后一点(最后触摸位置)。
- 如果是这样,请关闭路径。
- Store the touches locations (points) in an array:
[yourArray addObject:[NSValue valueWithCGPoint:yourPoint]];
- Make a rect (size? your choice! the smaller it is, the more precise) around the first point in the array (first touch location).
- Control if the rect also contains the last point in the array (last touch location).
- If so, then close your path.
这篇关于检测SKShapedNode已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文