[英]SpriteKit SKTexture mipmap doesn't work
我无法弄清楚如何为 SKTexture 纹理应用 mipmap。 我在 Swift 中使用 XCode 8.2.1。
这是我的方法:
override func sceneDidLoad() {
logo = childNode(withName: "logo") as! SKSpriteNode
let texture: SKTexture! = SKTexture.init(imageNamed: "logo")
texture.usesMipmaps = true
logo.texture = texture
}
我使用示例图像 png 512 * 512 大小(罐两个)全尺寸它看起来像这样:
然后我想把它的大小减小到 128*128 像素
他们俩看起来都一样。 所以我认为 mipmaps 不适用。 请帮助我,我花了 3 天时间尝试解决此问题。
UPD:正如Confused告诉我的那样,我在代码中完成了所有工作。 创建启用 mipmaping 的纹理,将其分配给 SKSpriteNode,然后通过缩放方法或操作执行缩放。
let texture = SKTexture.init(imageNamed: "logo")
texture.usesMipmaps = true
logo = SKSpriteNode.init(texture: texture)
logo.position = CGPoint(x: 0, y: 0)
self.addChild(logo)
//logo.scale(to: CGSize(width: 128, height: 128))
let scaleAction = SKAction.scale(to: CGSize(width: 128, height: 128), duration: 1)
logo.run(scaleAction)
如果 Xcode SpriteKit 场景编辑器在您的代码激活 mipmapping 之前调整您的纹理大小,一点也不奇怪。 这意味着您的纹理的 128x128 版本具有 mipmapping,因为这是 Xcode 和 SpriteKit SceneEditor 合谋存储为纹理的内容。
因此,不要在场景编辑器中设置比例,在代码中打开 mipMapping 后,使用它来缩放 SKSpriteNode:
https://developer.apple.com/reference/spritekit/skspritenode/1645445-scale
和/或试验 SKAction 缩放操作:
https://developer.apple.com/reference/spritekit/skaction
通过这种方式,您可以绝对确定事件的顺序是
希望这有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.