简体   繁体   中英

SpriteKit SKTexture mipmap doesn't work

I cannot figure it out how to apply mipmaps for SKTexture texture. I'm using XCode 8.2.1 with Swift.

Here is my method:

override func sceneDidLoad() {
    logo = childNode(withName: "logo") as! SKSpriteNode
    let texture: SKTexture! = SKTexture.init(imageNamed: "logo")
    texture.usesMipmaps = true
    logo.texture = texture
}

I use sample image png 512*512 size (pot both) Full size it looks like this: 全尺寸图像

Then I want to decrease its size to 128*128 pixels

缩小尺寸

And here is the output with mipmapping enabled: 启用 mipmapping 的输出 128*128

And for example output without mipmapping (only default linear filtering) 没有mipmapping

They both looks the same. So I think mipmaps didn't apply. Help me please, I've spent 3 days trying solve this problem.

UPD: As Confused told me, I made all job in code. Created texture with mipmaping enabled, assign it to SKSpriteNode and then perform scaling by scale method or action.

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)

Result is the same: 在此处输入图片说明

It wouldn't surprise, at all, if the Xcode SpriteKit Scene Editor is doing the resizing of your texture before the mipmapping is activated by your code. Meaning a 128x128 version of your texture has mipmapping on, because that's what Xcode and SpriteKit SceneEditor have conspired to store as a texture.

So instead of setting the scale in the Scene Editor, after turning on mipMapping in your code, use this to scale the SKSpriteNode:

https://developer.apple.com/reference/spritekit/skspritenode/1645445-scale

and/or experiment with the SKAction scaling operations:

https://developer.apple.com/reference/spritekit/skaction

In this way you can be absolutely sure that the sequence of events is

  1. Turn on mipmapping
  2. Perform Scaling

And hopefully this works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM