简体   繁体   中英

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!

You need to use the e xact same name of your font . So if you want to use the Impact Regular font, you need to call it like that:

SKLabelNode(fontNamed: "Impact Regular")

Without the - .

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM