Sprite Kit OS X: SKTexture size property is incorrect

后端 未结 2 1238
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 17:55

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 wh

相关标签:
2条回答
  • 2020-12-10 18:36

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

    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.

    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.

    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.

    0 讨论(0)
  • 2020-12-10 18:42

    Do you create texture with regular methods or actually show it on screen? I had similar issue with animations today, and I think this has to do with lazy lading of textures. They don't actually load until the time you have to use them. Try using this and checking size:

        [tempTexture preloadWithCompletionHandler:^{}];
    

    This also might explain why the rect is 0,0,1,1

    0 讨论(0)
提交回复
热议问题