Displaying random text using SKLabelNode

55 views Asked by At

I'm new to this sprite kit.I want to display the text randomly.Actually i'm having 3 words i need to display those 3 words randomly using SKLabelNode.I don't know how to implement this.Let us take Air,Land and sea these 3 words should be randomly displayed .please help me regarding this issue.Thanks in Advance.

 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

There are 2 answers

3
Droppy On BEST ANSWER
scoreLbl.text = @[@"Air", @"Land", @"Sea"][arc4random() % 3];
5
App Developer On

I Got the answer.I have given my code as scoreLbl.text= @[@"Air", @"Land", @"Sea"][arc4random() % 3];

Thank guys for helping me