1

我有以下UIBezierPath這就像一個圓,但在它的縫隙: enter image description here無碰撞檢測用SKShapeNode與UIBezierpath

var centerPosition = CGPointMake(self.frame.width/2, self.frame.height/2) 
var aPath:UIBezierPath = UIBezierPath(arcCenter: centerPosition, radius: 75, startAngle: 0, endAngle: degreesToRadians(size), clockwise: true) 
gapeCircle = SKShapeNode(path: myPath, centered: true) 

現在,我想用SKPhysicsBody使當一個對象碰撞到這個對象的輪廓時,就會發出通知。但只有在這種情況下。如果物體在間隙位置「碰撞」,則不應該有通知。

但我找不出如何解決這個問題。我已經嘗試了多種不同的SKPhysicsBody-initializers。唯一能夠工作的是circleOfRadius,但這並不像我想要的那樣工作,因爲我只有在對象與我的圈子的「非間隙」部分碰撞時才需要檢查碰撞。

回答

0

我懷疑這是因爲你沒有使用封閉的UIBezierPath。下面的代碼將創建一個循環曲線,給出'C'的寬度僅爲1 pt

var centerPosition = CGPointMake(self.frame.width/2, self.frame.height/2) 
var aPath:UIBezierPath = UIBezierPath(arcCenter: centerPosition, radius: 75, startAngle: 0, endAngle: degreesToRadians(size), clockwise: true) 
var aPath:UIBezierPath = UIBezierPath(arcCenter: centerPosition, radius: 74, startAngle: degreesToRadians(size), endAngle: 0, clockwise: false) 
gapeCircle = SKShapeNode(path: myPath, centered: true) 
+0

非常感謝您的回答。我會檢查我什麼時候回家。 – Christian 2014-12-12 13:58:43

+0

是否做到了這一招?和節日快樂! – 2014-12-23 07:36:08