小编use*_*536的帖子

如何设置随机颜色

这是我的代码的一部分:

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就可以了。怎么了

android colors libgdx

3
推荐指数
1
解决办法
1203
查看次数

按钮不会旋转libGDX

我想旋转一个按钮.因此我写了以下代码:

public void show () {
        skin2 = new Skin (Gdx.files.internal("SettingsButton.json"));
        button2 = new Button(skin2);
        button2.setPosition(25,1440);
        button2.setSize(120,120);
        button2.setOrigin(button2.getWidth() / 2, button2.getHeight() / 2);
        button2.addAction(Actions.repeat(RepeatAction.FOREVER,
                Actions.sequence(
                        Actions.rotateBy(360, 1), 
                        Actions.rotateTo(0))));
        button2.addListener(new ClickListener(){
            @Override
            public void clicked(InputEvent event, float x, float y) {
                game.setScreen(new SettingsScreen(game));
                super.clicked(event, x, y);
            }
        });

        stage.addActor(button2);
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,按钮没有旋转,但我不知道为什么.我该如何改进我的代码?

java android rotation button libgdx

3
推荐指数
1
解决办法
239
查看次数

标签 统计

android ×2

libgdx ×2

button ×1

colors ×1

java ×1

rotation ×1