use*_*536 3 android colors libgdx
这是我的代码的一部分:
Color[] color = new Color[3];
color [0] = Color.red;
color[1] = Color.blue;
color[2] = Color.yellow;
stage.getBatch().setColor(color[rand.nextInt()]);
Run Code Online (Sandbox Code Playgroud)
但是“ color [rand.nextInt()]);” 带红色下划线。我真的不知道为什么。括号中必须有四个数字或“ Color.BLUE”,但我想随机着色精灵。因此,我创建了一个具有三种颜色的数组。我认为只要给他们数字并使用rand.nextInt就可以了。怎么了
您可以生成如下的随机颜色:
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
Run Code Online (Sandbox Code Playgroud)