0
我有一個遊戲,我希望背景的屏幕顏色每10點從一種顏色過渡到另一種顏色。下面是我創建嘗試的方法:如何實現背景屏幕顏色轉換?
private void backgroundColorswitch(Rectangle rect) {
int color = mainView.getSolidColor(); /*I am trying to get the mainView's color for the transition's start color*/
int red = (color >> 16) & 0xFF;
int green = (color >> 8) & 0xFF;
int blue = (color >> 0) & 0xFF;
int alpha = (color >> 24) & 0xFF;
colorFade = ObjectAnimator.ofObject(mainView, "backgroundColor", new ArgbEvaluator(), Color.argb(alpha, red, green, blue), rect.getColor() - 1000000); /*I want the transition to end on a faded version of the color of the rectangles that also change every 10 points*/
colorFade.setDuration(2000); //length of transition
mainView.post(new Runnable() {
@Override
public void run() {
colorFade.start(); //Runs the animation
}
});
}
的每10個部分的照顧,但我想知道是否有更好的方法來進行此事。如何獲取FrameLayout的顏色,因爲顏色變化結束的顏色是正確的,但是當我使用mainView.getSolidColor()
獲取佈局的當前顏色時,過渡將以灰白色而不是佈局的當前顏色開始。
任何解決方案或建議非常感謝!