Search code examples
iosskspritenodesklabelnode

Displaying random text using SKLabelNode


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

Solution

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