使用SKLabelNode显示随机文本

时间:2015-06-11 13:29:57

标签: ios skspritenode sklabelnode

我是这个精灵套件的新手。我想随机显示文字。实际上我有3个单词我需要使用SKLabelNode随机显示这3个单词。我不知道如何实现这一点。让我们把Air,Land和sea这3个字随机显示出来。请帮我解决这个问题。谢谢你提前。

 SKLabelNode  * scoreLbl =  [SKLabelNode labelNodeWithFontNamed:@"Futura-Bold"];
[scoreLbl setText:@"Sea"];



[scoreLbl setFontSize:50*_distanceMultiPlayer];


[scoreLbl setPosition:CGPointMake(scoreLbl.position.x, scoreLbl.position.y + (10 *_distanceMultiPlayer) )];
scoreLbl.fontColor=[UIColor blueColor];
[scoreLbl setFontSize:12.0];
[self     addChild:scoreLbl];
[scoreLbl setName:@"scoreLabel"];

2 个答案:

答案 0 :(得分:2)

scoreLbl.text = @[@"Air", @"Land", @"Sea"][arc4random() % 3];

答案 1 :(得分:1)

我得到了答案。我给了我的代码为scoreLbl.text = @ [@" Air",@" Land",@" Sea"] [arc4random()%3];

感谢各位帮帮我