本文介绍了Sprite Kit OS X:SKTexture大小属性不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在OS X版本的Sprite Kit上测试游戏,发现某些纹理错误地报告了它们的大小.我想知道是否还有其他人看到此问题,是否有解释?

I'm testing a game on the OS X version of Sprite Kit, and find that some textures report their size incorrectly. I'm wondering if anyone else is seeing this problem and whether there is an explanation for it?

在我将其报告为错误之前,请先排除所有其他问题.如果这是已知的错误,请这样说.

Just to rule out any other issues before I report this as a bug. If this is a known bug, please say so.

我正在加载此纹理,它的大小为256x256像素:

I'm loading this texture, it is 256x256 pixels in size:

当我记录从该图像创建的SKTexture时,SKTexture描述为我提供了正确的尺寸,但size属性却没有,它表示图像为204.8 x 204.8.

When I log the SKTexture created from this image, then the SKTexture description gives me the correct size but the size property does not, it says the image is 204.8 x 204.8.

tex = <SKTexture> 'Tileset_GeometryB.png' (256 x 256)
tex.size = {204.80000000000001, 204.80000000000001}  // Huh? WTF?!?
tex.textureRect = {{0, 0}, {1, 1}}

我在iOS模拟器和设备上使用相同的代码加载了完全相同的纹理-size属性始终正确:256x256.

I load the exact same texture using the same code on iOS Simulator and device - size property is always correct: 256x256.

我还尝试先加载此纹理,以免产生任何可能的副作用.仍然是纹理大小错误.

I also tried loading this texture before anything else just to avoid any possible side effects. Still the texture size is wrong.

值得注意的是,并非所有纹理都会发生这种情况,但在我加载的所有256x256纹理上都会发生这种情况.一个128x256的纹理会正确报告其大小.

It is worth noting that this doesn't happen with all textures, but does happen on all 256x256 textures I load. A 128x256 texture reports its size correctly.

我也做了一个干净的构建,并且正在使用Xcode 5.0.1(5A2053)在Mavericks(13A603)上进行测试.

I also did a clean build, and I'm testing on Mavericks (13A603) with Xcode 5.0.1 (5A2053).

推荐答案

显然,此问题是由不兼容的图像程序引起的,在我看来,Inkscape一直是罪魁祸首.

Apparently this issue is caused by incompatible image programs, in my case Inkscape was always the culprit.

由Inkscape创建的 PNG文件似乎可以正常工作,但会导致Sprite Kit错误地报告尺寸.在我遇到的每种情况下,解决方法都只是在 Seashore 中打开PNG文件,然后打开另存为"使用相同的文件名来强制程序重新保存PNG文件.

The PNG files created by Inkscape appeared to work correctly but cause Sprite Kit to report the size incorrectly. In every instance this happened to me, the fix was simply to open the PNG file in Seashore, then "Save As" under the same filename to force the program to re-save the PNG file.

我认为使用其他图像程序打开和保存也可能起作用,甚至预览版也可能有助于修复此问题或 PNGCrush .

I assume opening and saving with other image programs might work as well, perhaps even Preview might help to fix this or a command line tool like PNGCrush.

还有一定的一致性,因为据报道Inkscape纹理大小减小了20%,即256纹理为204.8,而1像素纹理为0.8.问题似乎出在Inkscape的ppi(每英寸像素)设置上,该设置不允许低于90 ppi的值.但是Photoshop的默认值为72 ppi,比默认值少20%.而且我认为Sprite Kit假定PNG为72 ppi,获得90 ppi图像,因此错误地(或正确地?)计算出PNG的大小比实际大小小20%.

There's also a certain consistency because Inkscape texture size is reported as 20% less, ie 204.8 for a 256 texture, or 0.8 for a 1-pixel texture. The problem seems to be with Inkscape's ppi (pixels per inch) setting, where it does not allow values below 90 ppi. But Photoshop's default is 72 ppi which is exactly 20% less. And I take it that Sprite Kit assumes the PNG to be 72 ppi, gets a 90 ppi image, and thus incorrectly (or correctly?) calculates the PNG's size as 20% less than what it actually is.

这篇关于Sprite Kit OS X:SKTexture大小属性不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:39