applyImpulse不工作

时间:2018-01-09 01:29:32

标签: swift xcode sprite-kit swift4

我有一个SKShapeNode,我无法应用冲动。我的问题是什么?感谢

代码:

        var ball = SKShapeNode()

        ball.path = UIBezierPath(roundedRect: CGRect(x:-ballWidth/2, y: -ballHeight/2, width: ballWidth, height: ballHeight), cornerRadius: 64).cgPath
        ball.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)
        ball.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(ballWidth / 2));
        ball.physicsBody?.affectedByGravity = false
        ball.physicsBody?.isDynamic = false
        ball.physicsBody?.categoryBitMask = ballCategory
        ball.physicsBody?.collisionBitMask = enemyCategory
        ball.physicsBody?.contactTestBitMask = enemyCategory
        ball.isHidden = false
        ball.fillColor = UIColor.blue
        ball.strokeColor = UIColor.white
        ball.lineWidth = 10
        ball.name = "ball"
        ball.zPosition = 0



        addChild(ball)

        ball.physicsBody?.applyImpulse(CGVector(dx: 50, dy: 50))

1 个答案:

答案 0 :(得分:4)

ball.physicsBody?.isDynamic = false意味着忽略冲动和其他力量。您需要将此设置为true。