SKTexture and the scale property of a UIImage

后端 未结 3 516
挽巷
挽巷 2021-02-06 01:06

Is there any reason why an SKTexture appears to ignore the .scale of an image when constructed via textureWithImage:?

I have one i

3条回答
  •  被撕碎了的回忆
    2021-02-06 01:23

    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).

提交回复
热议问题