SKShapeNode SKPhysicsBody问题

时间:2017-09-19 13:10:24

标签: ios swift skphysicsbody skshapenode

我有SKShapeNode我要添加SKPhysicsBody。这是SKShapeNode的代码:

    let width: CGFloat = 200//self.frame.width
    let height: CGFloat = self.frame.height
    rightBlocker.path = UIBezierPath(roundedRect: CGRect(x:-width/2, y: -height/2, width: width, height: height), cornerRadius: 50).cgPath

    rightBlocker.position = CGPoint(x: -75, y: self.frame.height / 2)
    rightBlocker.fillColor = UIColor.white
    rightBlocker.strokeColor = UIColor.white
    rightBlocker.lineWidth = 10
    rightBlocker.physicsBody?.affectedByGravity = false
    rightBlocker.physicsBody?.isDynamic = false
    addChild(rightBlocker)

我尝试使用以下代码行添加SKPhysicsBody

    rightBlocker.physicsBody = SKPhysicsBody(rectangleOf: (rightBlocker.frame.size))

但每当我这样做时,它就完全消失了。我做错了什么?

0 个答案:

没有答案