I'm trying to add an image in UIImage format to SpritKit's SKSpriteNode.
When converting a UIImage into a texture to SKTexture and adding it to SKSpriteNode, the image that takes into account the orientation of the image held by the UIImage is not displayed on the screen.
I tried the code below, but the result is identical.
Code1:
let image: UIImage?
let texture: SKTexture = SKTexture(image: image!)
ver imageNode = SKSpriteNode(texture: texture)
Code2:
let image: UIImage?
let cgImage = image?.cgImage
let ciImage = CIImage(cgImage: cgImage!)
let orientedImage = UIImage(cgImage: CIContext(options: nil).createCGImage(ciImage, from: ciImage.extent)!, scale: 0, orientation: image!.imageOrientation)
let texture: SKTexture = SKTexture(image: orientedImage)
ver imageNode = SKSpriteNode(texture: texture)
Code3:
let image: UIImage?
guard let cgImage = image?.cgImage else { return }
let orientedImage = UIImage(cgImage: cgImage, scale: image!.scale, orientation: .up)
let texture = SKTexture(image: orientedImage)
ver imageNode = SKSpriteNode(texture: texture)
Is there a way to ensure that the image orientation is taken into account when displayed?