gpt4 book ai didi

ios - 如何定义多个Texts并随机输出?

转载 作者:行者123 更新时间:2023-11-29 10:39:58 25 4
gpt4 key购买 nike

我有一个 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 标签中随机调用它们?

最佳答案

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];

关于ios - 如何定义多个Texts并随机输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25043421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com