Guest User

Untitled

a guest
Jan 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. //
  2. // GameScene.swift
  3. // Pong
  4. //
  5. // Created by Mac2 on 1/16/17.
  6. // Copyright © 2017 Mac2. All rights reserved.
  7. //
  8.  
  9. import SpriteKit
  10. import GameplayKit
  11.  
  12. class GameScene: SKScene
  13. {
  14. var trump = SKSpriteNode()
  15. var player = SKSpriteNode()
  16. var opponent = SKSpriteNode()
  17.  
  18. override func didMove(to view: SKView)
  19. {
  20. //essentially link them to the physical nodes we created in the gamescene
  21. trump = self.childNode(withName: "trump") as! SKSpriteNode
  22. player = self.childNode(withName: "player") as! SKSpriteNode
  23. opponent = self.childNode(withName: "opponent") as! SKSpriteNode
  24.  
  25. //to initialize the game we need the ball to be going somewhere so we make it go on an angle to the player (not opponent)
  26.  
  27. trump.physicsBody?.applyImpulse(CGVector(dx: -20, dy: -20))
  28.  
  29. let border = SKPhysicsBody(edgeLoopFrom: self.frame)
  30. //create variable representing the frame or border of the gamescene
  31.  
  32. border.friction = 0 //we don't want friction to the borders
  33. border.restitution = 1.0 //we want bouncyness to the borders
  34.  
  35. self.physicsBody = border //wrap it all up and save it as the physics representation of the gamescene frame
  36. }
  37.  
  38. override func update(_ currentTime: TimeInterval)
  39. {
  40. // Called before each frame is rendered
  41. }
  42. }
Add Comment
Please, Sign In to add comment