gpt4 book ai didi

android - 如何设置随机颜色

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:41 26 4
gpt4 key购买 nike

这是我的代码的摘录:

Color[] color = new Color[3];
color [0] = Color.red;
color[1] = Color.blue;
color[2] = Color.yellow;
stage.getBatch().setColor(color[rand.nextInt()]);

但是“颜色[rand.nextInt()]);”带有红色下划线。我真的不知道为什么。括号中必须有四个数字或代替“Color.BLUE”,但我想随机给 Sprite 着色。因此我创建了一个包含三种颜色的数组。我认为只要给他们数字并使用 rand.nextInt 就可以了。错误是什么?

最佳答案

您可以像这样生成随机颜色:

Random rnd = new Random(); 
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));

关于android - 如何设置随机颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45324594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com