问题
I want to use a pixel font in my SpriteKit game.
But I can't use a bitmap font because I need to support many languages (too many characters).
So I should use a ttf font file.
I tried the following code, but characters were blurred by anti-aliasing.
let myLabel = SKLabelNode(fontNamed:"My-Pixel-Font")
myLabel.text = "Hello"
myLabel.fontSize = 10
myLabel.position = CGPoint(x: 100.0, y: 100.0)
myLabel.fontColor = SKColor.GrayColor()
self.addChild(myLabel);
Is there a good way to disable anti-aliasing in SKLabelNode?
My English is not good.
Thank you.
回答1:
You can call [textureFromNode:]
method on your SKView
to get your SKLabelNode
's texture, set it's filteringMode
property to SKTextureFilteringNearest
and create new SKSpriteNode
with that texture.
回答2:
Swift 4
let label = SKLabelNode()
label.text = "Test"
let node = SKSpriteNode(texture: view.texture(from: label))
node.texture?.filteringMode = .nearest
addChild(node)
来源:https://stackoverflow.com/questions/36788246/how-to-disable-anti-aliasing-in-sklabelnode