iPhone 5、6 和 6 plus 的 SpriteKit SKScene 大小
SpriteKit SKScene size for iPhone 5, 6 and 6 plus
我正在尝试使用 SpriteKit 为 iPhone 5,6 和 6 plus 构建应用程序。我为每个分辨率创建了一个背景图像:
image-1.png // of size 1136 x 640, for iPhone 5
image-1@x2.png // of size 1334 x 750, for iPhone 6
image-1@x3.png // of size 2208 x 1242, for iPhone 6 plus
在Xcode 7 中,当我运行 我在模拟器上的代码为iPhone 6 和6 加上正确和相应的图像被自动选择。但是当我 运行 iPhone 5 的代码时,选择了 iPhone 6 图像 (image-1@x2.png) 而不是正确的图像 (image-1.png).为什么?
在 SKScene.didMoveToView() 中,我将场景大小设置为视图的帧大小:
self.size = view.frame.size
当我将图像添加到场景时:
self.addChild(SKSpriteNode(imageNamed:"image-1"))
如果我使用 "image-1.png",我得到相同的结果。
没有专门为iPhone 5和6拍摄的地方。他们都拍摄了@2x图像。所以在这两种设备中它都会选择@2x 图像。
您需要以编程方式或基于条件进行设置。
参考我的老问题:Images.xcassets taking wrong image for the iPhone 6?
我正在尝试使用 SpriteKit 为 iPhone 5,6 和 6 plus 构建应用程序。我为每个分辨率创建了一个背景图像:
image-1.png // of size 1136 x 640, for iPhone 5
image-1@x2.png // of size 1334 x 750, for iPhone 6
image-1@x3.png // of size 2208 x 1242, for iPhone 6 plus
在Xcode 7 中,当我运行 我在模拟器上的代码为iPhone 6 和6 加上正确和相应的图像被自动选择。但是当我 运行 iPhone 5 的代码时,选择了 iPhone 6 图像 (image-1@x2.png) 而不是正确的图像 (image-1.png).为什么?
在 SKScene.didMoveToView() 中,我将场景大小设置为视图的帧大小:
self.size = view.frame.size
当我将图像添加到场景时:
self.addChild(SKSpriteNode(imageNamed:"image-1"))
如果我使用 "image-1.png",我得到相同的结果。
没有专门为iPhone 5和6拍摄的地方。他们都拍摄了@2x图像。所以在这两种设备中它都会选择@2x 图像。
您需要以编程方式或基于条件进行设置。
参考我的老问题:Images.xcassets taking wrong image for the iPhone 6?