android - Synchronize color changing in onDraw -
i have android game. change color scheme on touch. code is:
if(rect_dark.contains(x, y)) { isdark = !isdark; invalidate(); } then in ondraw method:
if(isdark){ this.setbackgroundcolor(getresources().getcolor(r.color.black_color)); } else{ this.setbackgroundcolor(getresources().getcolor(r.color.light_color)); } if(isdark){ mscorepaint.setcolor(getresources().getcolor(r.color.light_color)); } else{ mscorepaint.setcolor(getresources().getcolor(r.color.black_color)); } so, when press button changings of color not synchronized. @ first background color changed , text color. eyes see that.
how deal problem? answers.
maybe improve performance enough:
private int mcurrentcolor; if(rect_dark.contains(x, y)) { isdark = !isdark; if (isdark) { mcurrentcolor = getresources().getcolor(r.color.dark_color); } else { mcurrentcolor = getresources().getcolor(r.color.light_color); } invalidate(); } this avoids color assignments in ondraw method. if still unsatisfactory, might try double buffering, mentioned here.
Comments
Post a Comment