为什么我的顶部和底部物理体不会为iPad重新调整大小?

时间:2015-07-21 03:56:54

标签: ios swift skphysicsbody

我的屏幕底部和顶部有一个物理实体。它非常适合我的iPhone,但是当我去iPad模拟器时,距离屏幕顶部和屏幕底部几英寸。由于某些原因,它不适合iPad的屏幕边缘。有人可以帮我弄这个吗?谢谢!下面是使用代码的代码:

let wall1 = SKSpriteNode(color: SKColor.clearColor(), size: CGSize(width: 2000, height: 5))
let wall2 = SKSpriteNode(color: SKColor.clearColor(), size: CGSize(width: 2000, height: 5))


   func wall() {


    //top wall border
    wall1.position  = CGPointMake(self.frame.width / 2, self.size.height / 1.1)
    wall1.physicsBody  = SKPhysicsBody(rectangleOfSize: wall1.size)
    wall1.physicsBody!.dynamic  = false
    wall1.physicsBody!.categoryBitMask  = SideBlockCategory
    wall1.physicsBody!.restitution = 0
    wall1.physicsBody?.contactTestBitMask = HeroCategory
    wall1.physicsBody?.collisionBitMask = 0
    wall1.physicsBody?.usesPreciseCollisionDetection = true


    //bottom wall border
    wall2.position  = CGPointMake(self.frame.width / 2, self.size.height / 8.0)
    wall2.physicsBody  = SKPhysicsBody(rectangleOfSize: wall2.size)
    wall2.physicsBody!.dynamic  = false
    wall2.physicsBody!.categoryBitMask  = SideBlockCategory
    wall2.physicsBody!.restitution = 0
    wall2.physicsBody?.contactTestBitMask = HeroCategory
    wall2.physicsBody?.collisionBitMask = 0
    wall2.physicsBody?.usesPreciseCollisionDetection = true


    }

1 个答案:

答案 0 :(得分:0)

试试这个;

//top wall border
wall1.position  = CGPointMake(self.frame.width / 2, self.frame.height - 2.5)

//bottom wall border 
wall2.position  = CGPointMake(self.frame.width / 2, 2.5)