设置自定义顶部/底部边界

时间:2016-01-28 17:34:33

标签: ios swift sprite-kit

我将边界设置为屏幕的顶部和底部边缘,但我想知道如何在同一屏幕上的两个矩形内设置顶部/底部边界?

   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)

1 个答案:

答案 0 :(得分:1)

您应该尝试在以下位置更改self.frame:

self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)

到您的自定义设置。