Is there any reason why an SKTexture
appears to ignore the .scale
of an image when constructed via textureWithImage:
?
I have one i
From apples doc's of UIImage
On a device running iOS 4 or later, the behavior is identical if the device’s screen has a scale of 1.0. If the screen has a scale of 2.0, this method first searches for an image file with the same filename with an @2x suffix appended to it. For example, if the file’s name is button, it first searches for button@2x. If it finds a 2x, it loads that image and sets the scale property of the returned UIImage object to 2.0. Otherwise, it loads the unmodified filename and sets the scale property to 1.0. See iOS App Programming Guide for more information on supporting images with different scale factors.
But according to textureWithImageNamed:
.
The new texture object is initialized with the name of the image file and then control returns immediately to your game. Sprite Kit loads and prepares the texture data when it is needed by your game.
When loading the texture data, Sprite Kit searches the app bundle for an image file with the specified filename. If a matching image file cannot be found, Sprite Kit searches for the texture in any texture atlases stored in the app bundle. If the specified image does not exist anywhere in the bundle, Sprite Kit creates a placeholder texture image.
From the above textureWithImageNamed:
and SKTexture
doesn't care about scaling with device.(retina image).
I have the same behavior with textures from atlas created from a dictionary. On iOS 8.3
How to force SKTextureAtlas created from a dictionary to not modify textures size?
I've found this too and believe it's a bug. Not sure how Apple are going to rectify this as it could break existing code.
My workaround is to read the scale of the UIImage and then set the scale of the SKSpriteNode to 1.0 / scale. You need to do this for both the x and y scales of the SKSpriteNode.