This is a Swift package for creating SpriteKit labels using bitmap fonts generated by BMFont xml format compatible apps such as BMGlyph, BMFont and Glyph Designer 2
- add the package to your project through Xcode or by editing your Package.swift file and adding:
.package(url: "https://github.com/gabrielnica/bmglyph-swift.git", from: "1.0.0")
- import the library
import BitmapGlyphLabel
- create a font object
let font = BitmapGlyphFont(named: "myFont")
or
let cachedAtlas = ...
let font = BitmapGlyphFont(named: "myFont", usingAtlas: cachedAtlas)
if you already loaded the atlas in memory for caching purposes. It is recommended to also store the font for future use
- create a label node add it to your scene
let labelNode = BitmapGlyphLabel(text: "Some text", font: font)
self.addChild(labelNode)
By default the text is horizontally and vertically centered, with left justification. You can change this by modifying the .horizontalAlignment
, .verticalAlignment
and .justification
properties respectively. The text can also be modified after the label has been created by changing the, surprise, .text
property of the label
The node returned by BitmapGlyphLabel
is of type SKNode
. To get the total size of the node without computing it through SpriteKit you can access the .totalSize
property of the label