我正在尝试使用 SpriteKit SKRegion 类来计算封闭 CGPaths 的交集、差值、并集,但它似乎不起作用。这是一个简单的示例,我希望它能工作,但这里没有呈现任何内容。
CGPathRef a = CGPathCreateWithEllipseInRect(CGRectMake(0, 0, 100, 100), NULL);
CGPathRef b = CGPathCreateWithEllipseInRect(CGRectMake(50, 0, 100, 100), NULL);
SKRegion *ra = [[SKRegion alloc] initWithPath:a];
SKRegion *rb = [[SKRegion alloc] initWithPath:b];
SKRegion *rc = [ra regionByIntersectionWithRegion:rb];
CGPathRef c = [rc path];
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGContextAddPath(context, c);
CGContextFillPath(context);
渲染 a
和 b
有效,但 c
没有显示任何内容,尽管这些圆圈确实重叠。
其他场景也无法正常工作,例如对 a 和 b 使用基本矩形,甚至使用不对路径进行操作的不同 SKRegion 构造函数。
有什么想法吗?
最佳答案
如果您尝试渲染 ra.path,则需要使用非常高的值才能获得相同大小的圆圈。我使用了 3000 而不是 100,这样你就可以看到圆圈。
由于某种原因 rc 为零,所以它一定是一个错误或测试版功能。
关于objective-c - 区域与区域的交集 : not working in Sprite Kit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27239767/