关于如何使用SpriteKit中的SKLabelNode类插入换行符的简单问题。我有以下代码,但它不起作用-
SKLabelNode *nerdText = [SKLabelNode labelNodeWithFontNamed:@"Times"];
NSString *st1 = @"Test break";
NSString *st2 = @"I want it to break";
NSString *test = [NSString stringWithFormat:@"%@,\r%@",st1,st2]; //Even tried \n
nerdText.text = test;
nerdText.fontSize = 11;
nerdText.fontColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
nerdText.position = CGPointMake(150.0, 250.0);
[self addChild:nerdText];
请帮帮我!
最佳答案
我不认为可以,这是一种“破解”方式
SKNode *nerdText = [SKNode node];
SKLabelNode *a = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
a.fontSize = 16;
a.fontColor = [SKColor yellowColor];
SKLabelNode *b = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
b.fontSize = 16;
b.fontColor = [SKColor yellowColor];
NSString *st1 = @"Line 1";
NSString *st2 = @"Line 2";
b.position = CGPointMake(b.position.x, b.position.y - 20);
a.text = st1;
b.text = st2;
[nerdText addChild:a];
[nerdText addChild:b];
nerdText.position = CGPointMake(150.0, 250.0);
[self addChild:nerdText];