我有课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
的动态改变颜色。我想从0
to中获取价值255
并在for-loop
. 问题是loop
运行非常快。而且背景颜色变化非常快,如何减慢for-loop
或运行0
但255
不那么快?