SpriteKit physics in Swift - Ball slides against wall instead of reflecting

后端 未结 6 561
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 12:36

I have been creating my own very simple test game based on Breakout while learning SpriteKit (using iOS Games by Tutorials by Ray Wenderlich et al.) to see if I can apply co

6条回答
  •  失恋的感觉
    2020-12-01 13:14

    Add code below:

    let border = SKPhysicsBody(edgeLoopFrom: self.frame)
    border.friction = 0
    border.restitution = 1
    self.physicsBody = border
    

    which will make your ball bounce back when it collides with wall. Restitution is the bounciness of the physics body so setting it to 1 will bounce ball back.

提交回复
热议问题