Reputation: 185
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:
And for example output without mipmapping (only default linear filtering)
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)
Upvotes: 2
Views: 276
Reputation: 6288
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
And hopefully this works.
Upvotes: 1