A simple subclass of SKNode, which supports multiple line and automatic line breaking.
- Language: Swift 2.1
- Requirements: SpriteKit
This software is created by K.-C. Pan and can be included as a part of any software-project free of charge. No credits are required, but aknowledgement in any form is appreciated.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Display multiple line
- Automatic line breaking (by words, by characters, or by
"\n") - Dynamically add more text
- Autoclear text when filled
Just like the original SKLabelNode
let label = FPLabelNode(fontNamed:"Helvetica")Simple setup
label.width = CGRectGetMaxX(self.frame)
label.height = CGRectGetMaxY(self.frame)
label.position = CGPoint(x:CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame)
self.addChild(label)Full setup
label.width = CGRectGetMaxX(self.frame)
label.height = CGRectGetMaxY(self.frame)
label.fontColor = SKColor.blackColor()
label.fontSize = 40
label.spacing = 1.5
label.buffer = 80 // buffer for the edge
label.verticalAlignmentMode = .Center // default = .Center
label.horizontalAlignmentMode = .Center // default = .Center
label.splitMode = .Word // defulat = .Word
label.position = CGPoint(x: 20, y: CGRectGetMaxY(self.frame) - 50)
self.addChild(label)Push text
label.pushText("A string")Push an array of string
label.pushTexts(["Line 1","Line 2", "Line 3"])If you want to split your string by "\n",
label.pushString("This string\n can be \nsplit to \nfour lines.")Clear the text,
label.clear()Automatic break lines by characters. This is useful in some languages that words are not seperated by space (i.e. Chinese, Japanese, ...etc.).
label.splitMode = .Characterjust copy the FPLabelNode.swift to your project.