UImage loads entire SKTextureAtlas instead of just SKTexture

丶灬走出姿态 提交于 2020-04-18 12:49:49

问题


I need texture with 'trueName' to load into my myImageViewOutlet.image. The result I am getting is the entire atlas rendering into it. My code is as follows

let myTextureAtlas = SKTextureAtlas.init(named: "myGameTextures")

// let texture = myTextureAtlas.textureNamed(trueName) // will render the entire atlas, instead of just the texture by trueName

let texture = myTextureAtlas.textureNamed(trueName+”bad name“) // will produce the placeholder image by sprite kit by itself just fine, but it's not the one I want obviously

let image = texture.CGImage()

let newImage = UIImage(CGImage: image, scale: 1.0, orientation: UIImageOrientation.Up)
//        let newImage = UIImage(CGImage: image) // .. the straight forward way

myImageViewOutlet.image = newImage

回答1:


I reconciled image.CGImage() does not support textures from SKTextureAtlas, after reading a similar post SKTextures from SKTextureAtlas does not support mipmapping.

One approach is to form a SKTexture from SKView.textureFromNode(_ node: SKNode)

let textureToRender = myOffscreenView.textureFromNode(nodeToRender)

let newImage = UIImage(CGImage: textureToRender.CGImage())


来源:https://stackoverflow.com/questions/37189895/uimage-loads-entire-sktextureatlas-instead-of-just-sktexture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!