我有一个GameOverText标签。
gameoverText = [SKLabelNode labelNodeWithFontNamed:@"MarkerFelt-Thin"];
gameoverText.fontColor = [SKColor grayColor];
gameoverText.fontSize = 25;
gameoverText.position = CGPointMake(self.frame.size.width / 2, CGRectGetMidY(self.frame)+ CGRectGetMidY(self.frame)/1.6);
gameoverText.zPosition = 4;
gameoverText.text = [NSString stringWithFormat:@"Game Over!"];
[self addChild:gameoverText];
现在我想写几个文本。例如。 1.“你输了”,2。“游戏结束”,3。“再试一次”,4。“也许下一次”。
如何定义这些文本并在我的GameOverText标签中随机调用它们?
答案 0 :(得分:2)
gameoverText = [SKLabelNode labelNodeWithFontNamed:@"MarkerFelt-Thin"];
gameoverText.fontColor = [SKColor grayColor];
gameoverText.fontSize = 25;
gameoverText.position = CGPointMake(self.frame.size.width / 2, CGRectGetMidY(self.frame)+ CGRectGetMidY(self.frame)/1.6);
gameoverText.zPosition = 4;
int r0 = arc4random() % 4
switch (r0)
{
case 0:
gameoverText.text = @"You lose";
break;
case 1:
gameoverText.text = @"Game over";
break;
case 2:
gameoverText.text = @"Try again";
break;
case 3:
gameoverText.text = @"Maybe next time";
break;
default:
gameoverText.text = @"You lose";
break;
}
}
[self addChild:gameoverText];