屏幕的底部和顶部都有PhysicalBody。它非常适合我的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
}
最佳答案
尝试这个;
//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)