我需要在这种颜色切换之间获得随机颜色,以便将其放在标签上。
label1.color = ccBLUE;
label1.color = ccRED;
label1.color = ccGREEN;
label1.color = ccBLACK;
label1.color = ccYELLOW;
truckName.color = ccWHITE;
[label1 setColor:ccc3(160,32,240)];
label1.color = ccORANGE;
你能帮我一把吗?我从未使用过randoms
答案 0 :(得分:2)
完全随机颜色:
[label1 setColor:ccc3(rand()%255, rand()%255, rand()%255)];
您也可以设置一些限制:
[label1 setColor:ccc3(100+rand()%155, 150+rand()%105, 200+rand()%55)];
答案 1 :(得分:0)
int randColor = arc4random()%5;
switch(randColor)
{
case 0: default:
label1.color = ccBLUE;
break;
case 1:
label1.color = ccRED;
break;
case 2:
label1.color = ccGREEN;
break;
case 3:
label1.color = ccBLACK;
break;
case 4:
label1.color = ccYELLOW;
break;
}