ios - Spritekit - 不从 SKTextureAtlas 加载@3x 图像

标签 ios objective-c swift sprite-kit sktextureatlas

由于我的示例项目已被删除(我认为这会更容易测试),我将发布一些代码和图像来说明我的观点。

这里是示例图片

2x image

my 3x image

我的图集设置:

enter image description here

我的启动图像设置:

enter image description here

我将这些 Sprite 添加到场景中的代码

override func didMoveToView(view: SKView) {
    let texture = SKTextureAtlas(named: "scenery")
    let test = SKSpriteNode(texture: texture.textureNamed("test"))
    test.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
    self.addChild(test)

}

这些是我的结果:

iPhone 5 模拟器:

enter image description here

iPhone 6 plus 模拟器:

enter image description here

我已尝试更改启动图像以使用 Assets 目录。那么 iPhone 6 plus 似乎升级了 2 倍的屏幕。它仍在加载 2x 图像,但将其放大。

我需要它来加载我的 3 倍图像并缩放我的 2 倍图像。

Gabuh 在下面的回答为我指明了正确的方向。在一个新项目上工作。但是,如果我将他的解决方案用于我真正的 SpriteKit 项目,我的 3x 图像不会缩小。它们比应有的大 3 倍。

最佳答案

如果您正在使用一种新的方法来创建图集,它现在似乎可以正常工作。重要的是 Deployment target 应该 >= 9.0 ...

选择 Assets.xcassets 并点击 + 号创建一个新的 Sprite 图集:

enter image description here

选择“New Sprite Atlas”选项并添加@2x 和@3x 资源:

enter image description here

然后在代码中这样做:

let sprite = SKSpriteNode(texture: SKTextureAtlas(named: "Sprites").textureNamed("test"))
sprite.position = CGPoint(x: frame.midX, y: frame.midY)
addChild(sprite)

提示:

如果您在模拟器上进行测试,请在尝试之前重置模拟器的内容和设置以清除缓存。

关于ios - Spritekit - 不从 SKTextureAtlas 加载@3x 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28146685/

相关文章:

iphone - CGRectContainsRect 不工作

ios - NumberFormatter 在使用有效数字时不遵守 minimumFractionDigits

swift - 如何在swift中将字典添加到数组

ios - UITextView 的视差效果使顶部的 UIImageView 在 Swift 中缩小并消失

ios - iOS 和 watchOS 上的 CloudKit + CoreData 同步不起作用

ios - UITableView 重复 Firebase 数据

swift - SKSpriteNode - 中断 animateWithTextures 后纹理未恢复到原始大小

iphone - UIWindow 边界/框架为空

ios - Apple 拒绝了应用程序,因为 Info.plist 中启用了 UIBackgroundModes 音频

ios - 从 View Controller 返回到 TableView Controller 时 TableView 单元格 "jump"