Incrementing an integer on the display.

Fist time user here. I have come up with some code to increase or decrease a number on the screen with a button press. It works but I was wondering if there is a better way to do this than black out the old number before printing the new one on top of it. The only similar examples I have been able to find would, with each button press, erase and redraw the entire screen.

Is there a better way to redraw the number?

Here is the section of code from within the loop.

    // determine if a button has been pressed
    if ((XX >= 10 && YY >=85) && (XX <= 50 && YY < 115))
            {
            tft.setCursor(10,25);
            tft.setTextSize(3);
            tft.setTextColor(BLACK); 
            tft.println(ch1); 
            delay(100);
            ch1 = ch1 + 5;
            if (ch1 >= 255)
              { ch1 = 255; }
            tft.setCursor(10,25);
            tft.setTextColor(WHITE); 
            tft.println(ch1); 
            }
    if ((XX >= 10 && YY >=180) && (XX <= 50 && YY < 210))
            {
            tft.setCursor(10,25);
            tft.setTextSize(3);
            tft.setTextColor(BLACK); 
            tft.println(ch1); 
            delay(100);
            ch1 = ch1 - 5;
            if (ch1 <= 0)
              { ch1 = 0; }
            tft.setCursor(10,25);
            tft.setTextColor(WHITE); 
            tft.println(ch1);;
            }

There are different ways to erase text on a graphic LCD but none of them are necessarily any better.
if you don't want to specifically re-draw a given character or set of characters in black to erase it or them you can just do a rectangle fill for the pixels involved.
IIRC, for text size a 1 a char is 10x8, for size 2 its 20x16, etc.
the specific LCD library you are using probably matters.

I think the best way would be to use a monospaced front with a string drawing procedure which also erases the background for each glyph.

With ucglib it would look like this:

void setup(void) {
  ucg.begin(UCG_FONT_MODE_SOLID);  // ensure that the backround is erased for .print()
  ucg.clearScreen();
}
void loop(void) {
  ucg.setFont(ucg_font_ncenR14_tr);  // monospaced front
  ucg.setPrintPos(0,25);
  ucg.setColor(255, 255, 255);
  ucg.print("Hello World!");
  delay(500);  
}

@wg0z, this method does work fine but I thought there may be a simple solution I didn't know about. After all, in the small amount of other programming I have learned, if you want to change text somewhere you just tell it to change the text. Not erase and draw it again, just change it.

I thought about drawing rectangles after I posted this but method seems to be working fine and I already have the rest of the buttons complete.

@olikaus, that looks like much simpler method. I'll have to study up on it.

Thanks to both of you for helping out.