GTG101
GTG101

Reputation: 149

SpriteKit how to add a fixedJoint?

I'm trying to bind two nodes together with a fixed SKPhysicsJoint I came up with this Code:

var anchor = CGPointMake(hero.position.x + 10,hero.position.y)
var fixedJoint = [SKPhysicsJointFixed .jointWithBodyA(hero.physicsBody!, bodyB: shield.physicsBody!, anchor: anchor)]

the problem came with:

self.physicsWorld.addJoint(fixedJoint)

It gave me this error:

Cannot convert value of type '[SKPhysicsJointFixed]' to expected argument type 'SKPhysicsJoint'

Any help is appreciated.

Upvotes: 0

Views: 154

Answers (1)

crashoverride777
crashoverride777

Reputation: 10674

You put the fixedJoint into an array, try this instead, omitting [ and ].

let anchor = CGPointMake(hero.position.x + 10,hero.position.y)
let fixedJoint = SKPhysicsJointFixed.jointWithBodyA(hero.physicsBody!, bodyB: shield.physicsBody!, anchor: anchor)

Note: If you are not mutating your properties make them let instead of var.

Upvotes: 1

Related Questions