gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:27:16 30 4
gpt4 key购买 nike

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

这里是示例图片

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com