Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 应用脉冲不工作_Swift_Xcode_Sprite Kit_Swift4 - Fatal编程技术网

Swift 应用脉冲不工作

Swift 应用脉冲不工作,swift,xcode,sprite-kit,swift4,Swift,Xcode,Sprite Kit,Swift4,我有一个我不能冲动使用的SKShapeNode。我有什么问题?谢谢 代码: ball.physicsBody?.isDynamic=false表示忽略脉冲和其他力。您需要将其设置为true ball.physicsBody?.isDynamic=false表示忽略脉冲和其他力。您需要将其设置为true var ball = SKShapeNode() ball.path = UIBezierPath(roundedRect: CGRect(x:-ballWidt

我有一个我不能冲动使用的SKShapeNode。我有什么问题?谢谢

代码:


ball.physicsBody?.isDynamic=false
表示忽略脉冲和其他力。您需要将其设置为true

ball.physicsBody?.isDynamic=false
表示忽略脉冲和其他力。您需要将其设置为true

        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))