user10361497
user10361497

Reputation:

Binary operator '/' cannot be applied to operands of type 'CGSize' and 'Int'

I have a problem with the following code:

let torpedoNode = SKSpriteNode(imageNamed: "Torpedo")

torpedoNode.position = player.position
torpedoNode.position.y += 5

torpedoNode.physicsBody = SKPhysicsBody(circleOfRadius: torpedoNode.size / 2)

The error that I get is the line:

torpedoNode.physicsBody = SKPhysicsBody(circleOfRadius: torpedoNode.size / 2)

The error is:

Binary operator '/' cannot be applied to operands of type 'CGSize' and 'Int'

Upvotes: 3

Views: 847

Answers (1)

Rakesha Shastri
Rakesha Shastri

Reputation: 11242

CGSize is a struct which contains two CGFloat values - width and height.

So you cannot divide it with an Int.

It seems that your parameter requires a CGFloat anyway. So you should be dividing the height or width by 2 and passing instead.

torpedoNode.physicsBody = SKPhysicsBody(circleOfRadius: torpedoNode.size.width / 2) //or height whichever is appropriate

Upvotes: 2

Related Questions