gpt4 book ai didi

ios - UImage 加载整个 SKTextureAtlas 而不仅仅是 SKTexture

转载 作者:行者123 更新时间:2023-11-30 13:25:59 25 4
gpt4 key购买 nike

我需要带有“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

最佳答案

在阅读类似的文章 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())

关于ios - UImage 加载整个 SKTextureAtlas 而不仅仅是 SKTexture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37189895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com