1

我需要在这种颜色切换之间获得一种随机颜色,以便将其放在标签上。

                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;

你能帮我做吗?我从未使用过随机数

4

2 回答 2

2

完全随机颜色:

            [label1 setColor:ccc3(rand()%255, rand()%255, rand()%255)];

您还可以设置一些限制:

            [label1 setColor:ccc3(100+rand()%155, 150+rand()%105, 200+rand()%55)];
于 2013-07-30T14:18:50.780 回答
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;
}
于 2013-08-08T15:11:49.830 回答