Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import SpriteKit
  2.  
  3. class GameScene: SKScene, SKPhysicsContactDelegate {
  4.  
  5.  
  6. var node1:SKShapeNode
  7. var node2:SKShapeNode
  8. var node2PhysicsPath:CGPath
  9. var contactPoint:SKShapeNode
  10.  
  11.  
  12. required init?(coder aDecoder: NSCoder) {
  13.  
  14. contactPoint = SKShapeNode(circleOfRadius: 10)
  15. contactPoint.strokeColor = SKColor(calibratedRed: 1, green: 0, blue: 0, alpha: 1)
  16.  
  17. node1 = SKShapeNode()
  18. node1.position.x = 150
  19. node1.position.y = 200
  20. node1.physicsBody = SKPhysicsBody(circleOfRadius: 50)
  21. node1.physicsBody?.contactTestBitMask = 0xffffffff
  22. node1.physicsBody?.categoryBitMask = 0xffffffff
  23.  
  24.  
  25. node2PhysicsPath = CGPathCreateWithRect(CGRect(x: 0, y: 0, width: 100, height: 100), nil)
  26.  
  27. node2 = SKShapeNode()
  28. node2.physicsBody = SKPhysicsBody(polygonFromPath: node2PhysicsPath)
  29. node2.physicsBody?.dynamic = false
  30. node2.physicsBody?.contactTestBitMask = 0xffffffff
  31. node2.physicsBody?.categoryBitMask = 0xffffffff
  32.  
  33. super.init(coder: aDecoder)
  34.  
  35. physicsWorld.contactDelegate = self
  36. }
  37.  
  38. func didBeginContact(contact:SKPhysicsContact){
  39. println(contact.contactPoint);
  40. contactPoint.position = contact.contactPoint
  41. self.physicsWorld.speed = 0
  42. println(CGPathContainsPoint(node2PhysicsPath, nil, contact.contactPoint, true))
  43. }
  44.  
  45. override func didMoveToView(view: SKView) {
  46. self.addChild(node1)
  47. self.addChild(node2)
  48. self.addChild(contactPoint)
  49. self.physicsWorld.gravity = CGVector(dx: 0, dy: -1.0)
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement