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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -