Search code examples
macosswiftfontssprite-kitsklabelnode

Using custom font in SpriteKit for OSX in swift


So I'm trying to use a custom font "Impact". It works fine if the font is installed on the computer, but if it's not I can't seem to get it to work. I bring in the .ttf file to the project, add it to the info.plist like this:

Impact.ttf

And I've tried multiple methods for using that font on a SKLabel but nothing works. Here's what I've tried:

let restartLabel: SKLabelNode =  SKLabelNode(fontNamed: "Impact-Regular")
let restartLabel: SKLabelNode = SKLabelNode(fontNamed: "Impact")
let restartLabel: SKLabelNode = SKLabelNode(fontNamed: "Impact.ttf")

Any ideas? I would really appreciate the help, thanks!


Solution

  • The correct answer is here Custom font in a Cocoa application

    It turns out that the app didn't know where to look for the font, but setting the Application fonts resource path in info.plist made it work. I actually left the value blank since the font in just in MyApp.app/Contents/Resources/