0

I would like to know how to create a NSString that, when displayed, shows up on 2 lines. I've tried \n or @"\n" and nothing works.

    SKLabelNode *gameinstructions = [SKLabelNode labelNodeWithFontNamed:@"AvenirNext-Heavy"];
    gameinstructions.text = [NSString stringWithFormat:@"PLAY! \n  hello"];
    gameinstructions.fontColor = [self randomColor];
    gameinstructions.fontSize = [self convertFontSize:30];
    gameinstructions.zPosition = 0;
    gameinstructions.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;
    gameinstructions.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    SKAction *textFade = [SKAction fadeAlphaTo:0 duration:7];
    [gameinstructions runAction:textFade];
    [self addChild:gameinstructions];

So how do I get my app to display "hello" on a separate line from "play!"?

  • `\n` should work, as pointed out in various [other](http://stackoverflow.com/a/6420494/632736) [answers](http://stackoverflow.com/a/6420493/632736). – FreeAsInBeer Aug 18 '14 at 21:26
  • What kind of object 'gameinstructions' is? – almas Aug 18 '14 at 21:29
  • 1
    if its a UILabel, then make sure you set labelNode.numberOfLines to something greater than 1. – almas Aug 18 '14 at 21:35
  • @almas it is a SKLabelNode – Stefan Gergely Aug 18 '14 at 21:35
  • 1
    Well, the label's got to be capable of handling multiple lines. – Hot Licks Aug 18 '14 at 21:43
  • 1
    I think someone already asked this question: http://stackoverflow.com/questions/19179005/insert-line-break-using-sklabelnode-in-spritekit – almas Aug 18 '14 at 21:44
  • The view container `SKLabelNode` does not seem to support multi line text. Thus adding a line break character `\n` will not produce the desired result: two lines of text. (My answer will not work in this instance). – zaph Aug 19 '14 at 13:32
  • @Zaph It is OK, I used an image made in Photoshop to write my message with more lines and just put the image there :) – Stefan Gergely Aug 19 '14 at 13:34

1 Answers1

1

With the addition to the question of the container type SKLabelNode to the question it does not seem to support multi-line text. Thus adding a line break character \n will not produce the desired result: two lines of text.

In this instance this answer will not work.

For a line break:

gameinstructions.text = @"Play!\nhello";  

The line breakcharacter in iOS is \n.

But wether or not it will break when displayed will depend on the container supporting multiple lines.

BTW:

gameinstructions.text = [NSString stringWithFormat:@"Play!  hello"];

is redundant, simply:

gameinstructions.text = @"Play!  hello";. 
zaph
  • 111,848
  • 21
  • 189
  • 228
  • nope, doesn't work.... – Stefan Gergely Aug 18 '14 at 22:21
  • @StefanGergely I think you should listen to what Zaph is trying to tell you before just blowing off his answer. His code looks pretty good to me, and of you implement it in your app it should work. Maybe add some more info to your question so people can understand why this solution doesn't work, or why you're having trouble. – Jacob Aug 18 '14 at 22:28
  • @Jacob I did use his code in my app and I would gladly tell you what the issue is.. if I knew... it just seems to be ignoring the \n without going to a new line... – Stefan Gergely Aug 18 '14 at 22:42
  • @Stefan Gergely you need to tell us what contaioner class you are using for more help. – zaph Aug 18 '14 at 22:44
  • @StefanGergely I think you should post some more code about your label so we can understand the question better. – Jacob Aug 18 '14 at 23:06
  • @Jacob I will edit the question now – Stefan Gergely Aug 19 '14 at 09:43