drewvy22
drewvy22

Reputation: 65

Custom font causes delay in SpriteKit

I tried to change a label font to bodoni 72 but every time I test the app, it freezes for about 2 seconds before it starts. The default font is verdana and that works fine but as soon as I switch it, the app goes nuts. I even put the font file in the supporting files folder.

      scoreLabel.fontName = "Bodoni 72"

That's the code but doesn't work. But the code below does...

      scoreLabel.fontName = "Verdana"

Upvotes: 1

Views: 94

Answers (2)

Paulw11
Paulw11

Reputation: 114875

If you use the incorrect font name in SpriteKit it causes a delay while it tries to find a match.

In this case "Bodoni 72" is the font family name, but it isn't the font name. If you open the Font Book application on your Mac and have a look at Bodoni 72 you will see that you can expand it to see the three actual fonts in this family - 'Book', 'Book italic' and 'Bold'.

If you change your code to read

scoreLabel.fontName = "Bodoni 72 Book"

then the delay will be gone.

Upvotes: 3

DDPWNAGE
DDPWNAGE

Reputation: 1443

That's not an issue with Xcode or Swift. That's an issue in your code. Instead of that, try setting the fontName of your label to "Bodoni", and your fontSize (the size of your font as a float) to 72.0.

See below:

scoreLabel.fontName = "Bodoni"
scoreLabel.fontSize = 72

If you want to set the color of a label (this might only be in SpriteKit's SKLabelNodes), you can use this:

scoreLabel.fontColor = UIColor.whiteColor //replace with your color

Upvotes: -1

Related Questions