我正在基于Swift中的这篇博客文章http://labs.byhook.com/2011/09/26/vector-metaballs/中的第三个示例构建一个元球系统。当我拖动中间元球时,它可能会重叠右边或左边的元球(它们是静止的)。我想用“目标”剪辑固定的元球。元球(被拖的那个)。这是我简化的Metaball类
class Metaball: UIView {
let circlePathLayer = CAShapeLayer()
override init(frame: CGRect) {
super.init(frame: frame)
configure()
}
func configure() {
circlePathLayer.frame = bounds
circlePathLayer.lineWidth = 10
circlePathLayer.strokeColor = UIColor.blueColor().CGColor
layer.addSublayer(circlePathLayer)
}
func circleFrame() -> CGRect {
let circleFrame = CGRect(x: 0, y: 0, width: 2*circleRadius, height: 2*circleRadius)
return circleFrame
}
func circlePath() -> UIBezierPath {
return UIBezierPath(ovalInRect: circleFrame())
}
override func layoutSubviews() {
super.layoutSubviews()
circlePathLayer.frame = bounds
circlePathLayer.path = circlePath().CGPath
}
}
我试图在touchesEnded中的GameScene类中进行剪切方法。这是touchesEnded方法:
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
touching = false
let touch = touches.first
let touchLocation = touch!.locationInView(self)
target.center = touchLocation
var distPoints = dist(leftMetaball.center, pos2: touchLocation)
// if the distance between touchPoint and the center of the leftmetaball is less than the radius of a metaball x2 (200) they must be overlapping
if distPoints < 200 {
// clip leftMetaball path here
}
}
我希望两个相交的圆形成一个奇数形状的圆,其中一个贝塞尔曲线路夹住另一个以移除相交线。