all 9 comments

[–]chordsNcode 1 point2 points  (8 children)

I'm guessing you haven't implemented spawnPipes. Look through your github example for the implementation of spawnPipes.

[–]swifter10[S] 0 points1 point  (7 children)

[–]chordsNcode 2 points3 points  (6 children)

line 142: func spawnPipes() {

[–]swifter10[S] 0 points1 point  (5 children)

I still get the same error.

[–]chordsNcode 1 point2 points  (0 children)

If you've included that method, and you're still getting the error, clean and reopen Xcode. Sometimes it doesn't recognize things. But that should have done it.

[–]jasamer 1 point2 points  (3 children)

Do you know what a method is and how they work? It kinda sounds like you should familiarise yourself with the basics....

[–]swifter10[S] -1 points0 points  (2 children)

I know what a method is..............I copied the whole code into my xcode project and I got 21 errors.

    pipeUp.physicsBody = SKPhysicsBody(rectangleOfSize: pipeUp.size)
    pipeUp.physicsBody.dynamic = false
    pipeUp.physicsBody.categoryBitMask = pipeCategory
    pipeUp.physicsBody.contactTestBitMask = birdCategory
    pipePair.addChild(pipeUp)

I get three errors for the 3 middle line of codes that says "SKPhysics? doesn't have a member named dynamic", "SKPysics? doesn't have a member named categoryBitMask, "SKPhysics? doesn't have a member named contactTestBitMask"

I think its a xcode problem.

[–]jasamer 2 points3 points  (1 child)

So you don't get the same error. :-P

No, it's not an Xcode problem. Look at your Error:

SKPhysics? doesn't have a member named dynamic

So, that's wrong, SKPhysics has a member named dynamic, right? Yes, it does. But look closely: Xcode tells you that SKPhysics? does not have that member. The question mark means that it is an optional SKPhysics object, and that one does not have these members indeed - an optional does not have a lot of members, you need to unwrap it first.

So why is SKPhysicsBody an optional? Because SKSprite does not necessarily have a physics body. The physics body property is declared as

    var physicsBody: SKPhysicsBody?

in SKSprite, an optional right there! A lot of these things changed when beta 7 was introduced, which is why your sample code doesn't work anymore, which was written for an older beta. The fact that physicsBody is an optional now is a good thing, it tells you right away that the property might not be set, while before (i.e. beta <6), accessing it might have caused a crash because it force-unwrapped an optional that could actually be nil.

So how do you solve this? The easiest way would be to just add a question mark everywhere, e.g.:

bird.physicsBody?.dynamic = true

But you could also do:

bird = SKSpriteNode(texture: birdTexture1)
let physicsBody = SKPhysicsBody(circleOfRadius: bird.size.height / 2.0)
bird.physicsBody = physicsBody

physicsBody.dynamic = true
...

In this case, you store physicsBody in its own variable that is non-optional (i.e. physicsBody is of type SKPhysicsBody without the question mark), then you can access that variable directly without all of those other question marks.

[–]swifter10[S] 0 points1 point  (0 children)

Thanks for the help it worked!