Swift spriteKit的背景超出手机IOS的边框
我很难理解不同设备上的分辨率是如何工作的。所以我所做的是制作一个1024x768的背景图像,然后在iPhone5设备上进行测试。当我运行它时,屏幕的下半部分会被切掉,这样屏幕的上半部分也会被切掉。我确实使用AspectFill作为缩放模式,但即使在iPhone6或6+上进行测试,背景仍然被切断 以下是我的gameviewcontroller代码Swift spriteKit的背景超出手机IOS的边框,swift,sprite-kit,resolution,screen-size,Swift,Sprite Kit,Resolution,Screen Size,我很难理解不同设备上的分辨率是如何工作的。所以我所做的是制作一个1024x768的背景图像,然后在iPhone5设备上进行测试。当我运行它时,屏幕的下半部分会被切掉,这样屏幕的上半部分也会被切掉。我确实使用AspectFill作为缩放模式,但即使在iPhone6或6+上进行测试,背景仍然被切断 以下是我的gameviewcontroller代码 import UIKit import SpriteKit class GameViewController: UIViewC
import UIKit
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameScene(size: CGSize(width: 1024, height: 768))
let skView = self.view as! SKView
skView.multipleTouchEnabled = true
if GameSettings.Debugging.ALL_TellMeStatus {
skView.showsFPS = GameSettings.Debugging.ALL_ShowFrameRate
skView.showsNodeCount = GameSettings.Debugging.ALL_ShowNodeCount
skView.showsDrawCount = GameSettings.Debugging.IOS_ShowDrawCount
skView.showsQuadCount = GameSettings.Debugging.IOS_ShowQuadCount
skView.showsPhysics = GameSettings.Debugging.IOS_ShowPhysics
skView.showsFields = GameSettings.Debugging.IOS_ShowFields
}
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
_ = SGResolution(screenSize: view.bounds.size, canvasSize: scene.size)
skView.presentScene(scene)
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Landscape
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
以及我的代码,用于在中添加背景图像
let background = SKSpriteNode(imageNamed: "Artboard 1")
background.posByCanvas(0.5, y: 0.5)
background.xScale = 1.2
background.yScale = 1.2
background.size = self.frame.size
background.zPosition = -1
addChild(background)
这是开始屏幕大小的正确方法,还是我应该先开始使用iPad屏幕大小,然后再对其进行除垢?如果有人能指导我如何解决这个问题,那就太好了 方面填充将切掉你的部分背景 场景的纵横比为4:3 您的设备的纵横比为16:9
AspectFill
将按当前纵横比(4:3)缩放场景,直到填充最远的边框,从而使整个视图显示场景,并且没有黑色边框
AspectFit
将缩放,直到填充最近的边框,这将为您提供黑条以保留纵横比
如果您不想保留4:3,那么您可以使用.Fill
,这当然会使您的精灵在16:9更胖,因为它只会拉伸场景,直到它到达所有4个边界
最后你有了.ResizeFill
,它的作用是调整场景边界的大小以匹配你的屏幕大小,因此如果你从1024x768场景开始,当你在iPhone 6+上查看它时,它将变成736x414场景(这是因为我们在点而不是像素上工作,像素计数将是x3(因此2208x1242)哪些硬件将收缩到1920x1080)
你需要退后一步,评估你希望你的游戏在3种不同的纵横比下看起来如何
16:9、3:2和4:3,并确定上述4种方法中哪一种最适合您
现在在我看来,我发现纵横比填充效果最好,我只是计划采用16:9的纵横比,确保我不会在游戏中可能裁剪的区域中放置任何重要信息,但这并不适用于所有人,不幸的是,没有人能在这一部分为您提供帮助,因为这是你的游戏,你是决定它的外观和感觉的人