从SKTextureAtlasSpritekit——不是加载@3x图像 - Spritekit - not loading @3x images from SKTextureAtlas

- 此内容更新于:2016-01-20
主题:

因为我的示例项目被删除(我认为这将是更容易测试),我会发布一些代码和图片来说明我的观点。这里有样品图片我的阿特拉斯设置:发射图像设置:代码,我将这些精灵添加到场景这些是我的结果:iPhone5模拟器:iPhone6+模拟器:我试着改变发射图像使用资产目录。然后iPhone6+2x屏幕看起来高档。它仍然是加载2x形象,但尺度。我需要负载3x的形象,是规模与我2x的形象。Gabuh的回答我以下指出正确的方向。在一个新项目上工作。然而,如果我使用他的解决方案真正SpriteKit项目3x照片不要缩减规模。他们是3x比他们应该。

原文:

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.

Here are sample images

2x image

my 3x image

My atlas setup:

enter image description here

My launch image setup:

enter image description here

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)

}

These are my results:

iPhone 5 simulator:

enter image description here

iPhone 6 plus simulator:

enter image description here

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.

I need it to load my 3x image and be to scale with my 2x image.

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.

网友:你是测试一个真正的iPhone6+吗??或模拟器?

(原文:Are you testing on a real iPhone 6+ ?? or in the simulator?,)

网友:两者都有。你试过我的项目吗?

(原文:both. have you tried my project?)

网友:我删除了链接到项目。(疑似)源代码的问题应该在问题本身。所以用户不需要下载整个项目并开始调试/修改它。

(原文:I removed the link to the project. The (suspected) source code with the issue should be in the question itself. SO users shouldn't need to download an entire project and start debugging/modifying it.)

网友:好吧……我已经发布了大量的截图来说明我的观点。我发布一个简单的项目很感兴趣,因为人回答这个,假设它没有测试出来为自己工作。

(原文:alright... i've posted plenty of screenshots to illustrate my point. I was interested in posting a simple project because people are answering this and assuming it works without testing it out for themselves.)

网友:我将做测试,但也许你可以测试Xcode6.2,根据新的答案。

(原文:I will do testing as well but maybe you can test Xcode 6.2, according to the new answer below.)

解决方案:
似乎一个错误当Xcode生成编译后的阿特拉斯。如果你检查你的包内编译应用程序,您将看到Xcode不是@3x图像创建正确的阿特拉斯的名字。我成功得到@3x资产通过创建地图集@3x名字,没有后缀的形象。你可以检查决定使用阿特拉斯的名字。检查连接图像中的阿特拉斯的名字,里面的代码
原文:

It seems a bug when Xcode generates the compiled atlas. If you check inside the package of your compiled app, you will see that Xcode is not creating the correct atlas names for the @3x images.

I've managed getting the @3x assets by creating atlases with the @3x name, and leaving the image without the suffix.

And you can check for the UIScreen.mainscreen().scale to decide the atlas name to use. Check the atlas name in the attached image, and the code inside getTextureAtlas enter image description here

网友:你有试过在我的项目吗?我试过,还不拿起3x的形象。

(原文:have you tried this in my project? I tried it, and it's still not picking up the 3x image.)

网友:这是太棒了!完全在示例项目。除了当我复制这个为我真正的spritekit项目设置不降尺度3x图像。那边那些人都比他们应该3倍大!我不能告诉什么可能导致。什么好主意吗?如果我能解决这部分我在家自由。

(原文:this was great! totally worked on the sample project.. except when i copy this setup for my REAL spritekit project it's not downscaling the 3x images. theyre all 3x bigger than they should be! I can't tell what could be causing that. Any ideas? If I can figure that part out I'm home free.)

网友:我觉得这是相关项目的设置。我一直试图告诉我项目之间的差异但我真的不能找到它。

(原文:I feel like this is something related to the project's settings. I keep trying to tell the difference between my projects but I really cant find it.)

网友:好的我明白了..我在其他项目下构建设置了“输出纹理地图集格式”我RGBA8888_COMPRESSED选中。没有工作。我不得不将它设置为RGBA8888_PNG和清洁项目。

(原文:okay i got it.. in my other project under build settings i had set "Output Texture Atlas Format" I had RGBA8888_COMPRESSED selected. That didnt work. I had to set it to RGBA8888_PNG and clean project.)

网友:有一个更好的解决了吗?

(原文:Is there a better fix for this yet?)

解决方案:
Xcode6.2现在加载@3x和@2x图像的阿特拉斯。它加载大小1x(似乎调整图像的)如果你不把@2x/@3x最后图像的名字。
原文:

Xcode 6.2 now loads @3x and @2x images out of one atlas. It loads a 1x size (and seems to resize the image on its own) if you do not put @2x/@3x at the end of the image name.

网友:实际上我只是尝试但Xcode6.2仍然只加载一个为iPhone6+2x甚至纹理。所以Xcode6.2还窃听了。更糟糕的是:我看着地图文件。应用:3和1x图像最终在1x文件!!!

(原文:Actually I just tried this but Xcode 6.2 still only loads a 2x texture even for iPhone 6 Plus. So Xcode 6.2 is still bugged. What's worse: I looked at the resulting atlas files in the .app: the 3x AND 1x images end up in the 1x file!!!)

网友:你是对的!!我没有注意到这是加载@2x6+直到你说。这是真的搞砸了。

(原文:You are right!! I did not notice it was loading the @2x on my 6+ until you said that. This is really really screwed up.)

网友:@Whirlwind我仍然检查筛制所上面的回答。在2x阿特拉斯,我At2x图像名称后,在我3x地图集,图片只是图片的名字。它加载正确的阿特拉斯和规模似乎并没有图像。

(原文:@Whirlwind I still check the screen scale as mentioned in the answer above. In my 2x atlas, I have At2x after my image name, in my 3x atlas, the images are just the image name. It loads the correct atlas and does not seem to scale the images.)

网友:没有什么都没有为我工作。我只是一个建议重新创建我的艺术文件在photoshop中/插画家,并确保没有差距在网络层。对一些人来说显然已经修正这些问题。一开始我不认为有差距但无论如何我要试试。

(原文:No nothing has worked for me. I did just get a suggestion to recreate my art file in photoshop/illustrator, and make sure there are not gaps in the online layer. Apparently that has fixed these problems for some people. I didn't think there were gaps to begin with but I am going to try it anyway.)

网友:这是如此令人沮丧的…我想用@2x图片和做。恐怕上面的建议解决方案将不工作,这个问题是固定的,不会让你的精灵出现在固定ios版本。

(原文:This is so frustrating... I am thinking of using @2x images and be done with it. I'm afraid the suggested solution above will not work when this issue is fixed and will make your sprites to not appear on the fixed ios version.)

解决方案:
这个错误仍然没有解决。通过使用@2x图像视觉的应用被打破。相反,选择合适的图像通过屏幕比例。
原文:

This bug is still unsolved. By using just @2x images the visual of the app gets broken. Instead choose the right image by looking screen scale.

textureName = [UIScreen mainScreen].scale > 2.9 ? @"awesome@3x" : @"awesome";