Spritekit - 不从 SKTextureAtlas 加载 @3x 图像 [英] Spritekit - not loading @3x images from SKTextureAtlas
问题描述
由于我的示例项目被删除(我认为这会更容易测试),我将发布一些代码和图像来说明我的观点.
Since my sample project was deleted (I thought this would be much easier to test), I will post some code and images to illustrate my point.
这里是示例图片
我的地图集设置:
我的启动图像设置:
我将这些精灵添加到我的场景的代码
The code where I add these sprites to my scene
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 模拟器:
iPhone 5 simulator:
iPhone 6 plus 模拟器:
iPhone 6 plus simulator:
我已尝试更改启动图像以使用资产目录.然后 iPhone 6 plus 似乎升级了 2 倍屏幕.它仍在加载 2x 图像,但将其放大.
I've tried changing the launch image to use the asset catalog. Then the iPhone 6 plus seems to upscale a 2x screen. It's still loading the 2x image, but scales it up.
我需要它来加载我的 3x 图像并使用我的 2x 图像进行缩放.
I need it to load my 3x image and be to scale with my 2x image.
Gabuh 在下面的回答为我指明了正确的方向.在一个新项目上工作.但是,如果我将他的解决方案用于我真正的 SpriteKit 项目,我的 3x 图像不会缩小.它们比应有的大 3 倍.
Gabuh's answer below pointed me in the right direction. Works on a new project. However, if I use his solution for my real SpriteKit project my 3x images don't get downscaled. They are 3x bigger than they should be.
推荐答案
如果您正在使用一种新的方式来创建图集,它现在似乎可以工作了.重要的是 Deployment target
应该 >= 9.0 ...
It seems to be working now if you are using a new way to create atlas. Important thing is that Deployment target
should be >= 9.0 ...
选择Assets.xcassets
并点击+号创建一个新的精灵图集:
Select Assets.xcassets
and click to + sign to create a new sprite atlas:
选择New Sprite Atlas"选项并添加@2x 和@3x 资产:
Choose "New Sprite Atlas" option and add @2x and @3x assets :
然后在代码中这样做:
let sprite = SKSpriteNode(texture: SKTextureAtlas(named: "Sprites").textureNamed("test"))
sprite.position = CGPoint(x: frame.midX, y: frame.midY)
addChild(sprite)
提示:
如果您在模拟器上进行测试,请在尝试之前重置模拟器的内容和设置以清除缓存.
If you are testing on Simulator, reset Simulator's content and settings to clear the cache before you try this.
这篇关于Spritekit - 不从 SKTextureAtlas 加载 @3x 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!