How to disable anti-aliasing in SKLabelNode?

丶灬走出姿态 提交于 2019-12-12 01:38:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!