我有这个游戏是在风景,我需要一个边界周围的整个屏幕,所以我的heroNode不能走出屏幕的任何一方。我有这个代码,但它只适用于iphone 5s,对于其他设备来说它太小了。如何使代码调整大小并适合其他设备的屏幕?谢谢!
override func didMoveToView(view: SKView) {
let borderBody = SKPhysicsBody(edgeLoopFromRect: CGRect(x: 20, y: -90, width: self.size.width-50, height: self.size.height))
borderBody.categoryBitMask = borderbodycategory
borderBody.collisionBitMask = HeroCategory
borderBody.contactTestBitMask = HeroCategory
borderBody.allowsRotation = false
borderBody.affectedByGravity = false
self.physicsBody = borderBody
}
最佳答案
您可以使用UIScreen
的属性而不是固定值。
let width = UIScreen.mainScreen().bounds.size.width - 50
let height = UIScreen.mainScreen().bounds.size.height - 50
let borderBody = SKPhysicsBody(edgeLoopFromRect: CGRect(x: 20, y: -90, width: width, height: height))