0

我有课Background

public class Background extends Sprite {
    private Color color;
    private int COLOR_SIZE = 255;



    @Override
    void update(GameCanvas canvas, float deltaTime) {
        for (int i = 0; i < COLOR_SIZE ; i++) {
            color = new Color(
                    (int)(Math.random() * i),
                    (int)(Math.random() * i),
                    (int)(Math.random() * i)
            );
        }
    }

    @Override
    void render (GameCanvas canvas, Graphics g){
        g.setColor(color);
        g.fillRect(canvas.getX(), canvas.getY(), canvas.getWidth(), canvas.getHeight());
    }

}

我需要我background的动态改变颜色。我想从0to中获取价值255并在for-loop. 问题是loop运行非常快。而且背景颜色变化非常快,如何减慢for-loop或运行0255不那么快?

4

0 回答 0