Reputation: 83
I have boundaries set to the top and bottom edges of the screen, but I wanted to know how I would set top / bottom boundaries within two rectangles on the same screen?
override func didMoveToView(view: SKView) {
self.view!.backgroundColor = UIColor(patternImage: UIImage(imageLiteral: "bgImage"))
self.physicsWorld.gravity = CGVectorMake(0.0, -5.0)
self.physicsWorld.contactDelegate = self
blueBall = SKSpriteNode( imageNamed: "ball1111.png")
blueBall.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
blueBall.physicsBody = SKPhysicsBody(circleOfRadius: blueBall.size.width / 3.50)
blueBall.physicsBody!.dynamic = true
blueBall.physicsBody!.allowsRotation = true
self.addChild(blueBall)
blueBall.zPosition = 2
self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
let push = CGVectorMake(10, 10)
blueBall.physicsBody?.applyImpulse(push)
Upvotes: 1
Views: 77
Reputation: 816
You should try to change the self.frame in:
self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
to your custom settings.
Upvotes: 1