Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 1.38 KB

README.md

File metadata and controls

35 lines (24 loc) · 1.38 KB

BitmapGlyphLabel

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

Usage

  1. 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")
  2. import the library import BitmapGlyphLabel
  3. 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

  1. 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