How to disable anti-aliasing in SKLabelNode?

2019-09-13 18:42发布

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.

2条回答
Viruses.
2楼-- · 2019-09-13 19:13

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.

查看更多
你好瞎i
3楼-- · 2019-09-13 19:19

Swift 4

let label = SKLabelNode()
label.text = "Test"
let node = SKSpriteNode(texture: view.texture(from: label))
node.texture?.filteringMode = .nearest
addChild(node)
查看更多
登录 后发表回答