Reputation: 123
I have an SKShapeNode that I'm not able to apply an impulse to. What's my problem? Thanks
Code:
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))
Upvotes: 0
Views: 395
Reputation: 16827
ball.physicsBody?.isDynamic = false
means to ignore impulses and other forces. You need to set this to true.
Upvotes: 4