1

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.

Mac
  • 137
  • 1
  • 8

2 Answers2

3

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.

Vahan Babayan
  • 723
  • 7
  • 21
1

Swift 4

let label = SKLabelNode()
label.text = "Test"
let node = SKSpriteNode(texture: view.texture(from: label))
node.texture?.filteringMode = .nearest
addChild(node)
Hamer
  • 1,354
  • 1
  • 21
  • 34