We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › text() , erase_text() ?
Page Index Toggle Pages: 1
text() , erase_text() ?? (Read 687 times)
text() , erase_text() ??
Dec 2nd, 2007, 6:58am
 
Overwriting a text with spaces doesn't erase it.

How should I erase text ?

Here is my program:
(first you must use <Tools>/<Create Font...> to load the font)

//=================================
void setup() {
 size(120,120);
 noLoop();
 //
 PFont fontA;
 fontA = loadFont("dialog-12.vlw");
 textFont(fontA);
 //
 fill(0);
 text("aaaa", 5, 20);
 text("    ", 5, 20); //<< "aaaa" still there
 //
 for (int i=0; i<5; i++) text(str(i),60,20); //<< numbers overlap
 //
}

void draw() {
}
//=================================
Re: text() , erase_text() ??
Reply #1 - Dec 2nd, 2007, 8:39am
 
You can clear the screen with background() and draw it again.
Re: text() , erase_text() ??
Reply #2 - Dec 2nd, 2007, 8:45am
 
Yes but I don't want to clear the whole screen.

So I should write a rectangle of background color over the text.
Here is the result:(not elegant but it works)

//======================================
void setup() {
 size(120,120);
 background(204);
 noLoop();
 //
 PFont fontA;
 fontA = loadFont("dialog-12.vlw");
 textFont(fontA);
 //
 fill(0);
 text("aaaa", 10, 20);// write text
 noStroke();
 fill(204,204,204);
 rect(10,20-12,textWidth("aaaa"),12);// erase text
 stroke(0);
 //
 fill(0);
 for (int i=0; i<3; i++) {
   noStroke();
   fill(204,204,204);
   rect(50,20-12,textWidth("0"),12);// erase previous num
   stroke(0);
   fill(0);
   text(str(i),50,20);// write num
 }
 //
}

void draw() {
}
//======================================
Page Index Toggle Pages: 1