I ve got class 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());
}
}
I need for my background
to dynamically change color. I figured to get value from 0
to 255
and run it in for-loop
. Problem is loop
is run very fast. And color of background change very fast, how to slow for-loop
or run from 0
to 255
but not so fast?