The O.G. Virtual learning! Buy one, get 2 more Lifetime Memberships! - Click Here!

Issue in Contact Physics (SKPhysicsContact)

Home 4 Forums Swift and Sprite Kit Issue in Contact Physics (SKPhysicsContact)

This topic contains 3 replies, has 2 voices, and was last updated by  Justin 4 years, 10 months ago.

  • June 13, 2016 at 2:17 pm #151518

    Hey everyone, I’m having an issue in SKPhysicsContact in Sprite Kit. So I’m trying to make statement like “Player.destroy()” as taught in the Missile Commando course, or even “Player.hit()” but it gives me an error saying “Value of type ‘SKSpriteNode’ has no member ‘destroy'” Did I forget to add something in and thats whats causing this error?

    and if I do if let missile = contact.bodyA.node! as? Enemy { then type missile.destroy() the error would be “Use of undeclared type ‘Enemy'”

  • June 13, 2016 at 9:26 pm #151549

    Yeah, sounds like you didn’t cast something to make it sure it was a specific type of class other than SKSpriteNode. Basically its just tell you SKSpriteNode doesn’t have a function in it named destroy.

    For the second issue, try…

    if let missile:Enemy = contact.bodyA.node! as? Enemy {

    I’m not sure you need the exclamation mark. Try with and without.

    • June 14, 2016 at 1:29 pm #151615

      Hey Justin, so how exactly do I fix it? I’m a little confused

    • June 14, 2016 at 2:45 pm #151616

      Seems like both issues are the same. You need to be sure you’re successfully casting the node as your Player or Enemy before trying to run those functions.

You must be logged in to reply to this topic.

Know what an affiliate program is? You make money just by sharing links to our site! Win. Win.

Earn when you refer any buyer here! 30 day tracking. Commissions are 33%-50% and recur on subscription products!

Uh oh, missing your affiliate ID. Create one real quick