我需要带有'trueName'的纹理才能加载到myImageViewOutlet.image中。我得到的结果是整个地图集渲染到它。我的代码如下
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
答案 0 :(得分:0)
我在阅读了类似的帖子SKTextures from SKTextureAtlas does not support mipmapping之后,调整了image.CGImage()不支持SKTextureAtlas的纹理。
一种方法是从SKView.textureFromNode(_ node:SKNode)形成SKTexture
let textureToRender = myOffscreenView.textureFromNode(nodeToRender)
let newImage = UIImage(CGImage: textureToRender.CGImage())