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

标签 ios xcode sprite-kit

我有一个 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/

相关文章:

xcode_backend.sh : no such file or directory. 我需要创建这个文件吗?

ios - iOS 8 中的 SKShader,swift 中没有 GLVector?

ios - 如何在 swift 框架中使用 Objective C 桥接头?

ios - ios中uiscrollview的底部刷新控件

iphone - 内存泄漏仅出现在 iPhone 上

ios - 将 -exportArchive 与未签名的存档一起使用时是否可以指定权利文件?

swift - 命中 fatal error : unexpectedly found nil while unwrapping an Optional value (lldb)

swift - 不同模拟时间的 SKEmitterNode

iOS - malloc 有没有虚拟化

ios - 横向拖放图像不起作用