Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

\n not working in Sklabel SpriteKit

I have been using the following code in my game. The Problem is that i am unable to make multi-line label in spritekit as i was able to do using CCLabelTTF...... Can Somebody help me. Also i am unable to use either \t or \n in my code... Thanks for the reply in advance

SKLabelNode *winner = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
winner.text = @"Another\nTest";
winner.fontSize = 32;
winner.fontColor = [SKColor blueColor];
winner.position = CGPointMake(100 , 160);
[self addChild:winner];
like image 372
Umesh Sharma Avatar asked Sep 26 '13 13:09

Umesh Sharma


1 Answers

I had the same problem. I created a drop-in replacement for SKLabelNode called DSMultilineLabelNode that supports word wrap, line breaks, etc. The underlying implementation draws the string into a graphics context and then applies that to a texture on an SKSpriteNode.

It's available on GitHub at:

https://github.com/downrightsimple/DSMultilineLabelNode

like image 193
Chris Allwein Avatar answered Sep 28 '22 00:09

Chris Allwein