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 staying on screen
Page Index Toggle Pages: 1
Text staying on screen? (Read 775 times)
Text staying on screen?
Dec 2nd, 2008, 3:58am
 
Hello, everybody. I'm working on only my second program using Processing, and I'm having a problem. Here's an example of what I'm doing:

"int young = 0;
...

public void draw() {
text("young = " + young, 50, 50);
...}"

When I try to run this, it prints "young = " okay, but it doesn't erase the variable 'young' after each refresh; it writes the new number on top of the old one, making everything illegible. Did I miss something here?



Whole program:

import processing.core.*;

public class project2 extends PApplet {

int counter = 0;
//counter for current generation

int refresh = 6;
//frame rate

//resources

int fuel = 10000;
//nonrenewable

int water = 50000;

int animals = 500;

int plants = 5000;

//people

int young = 0;

int adults = 2;

int dead = 0;

//variable transitions

int birthCount = 2;

int animalCount = 2;

//create font

PFont myFont;


public void setup() {


//create window


frameRate(refresh);


size(1000,1000);


//setup font


myFont = createFont("verdana", 16);


textFont(myFont);


//load images

}


public void draw() {


//print variables


text("young = " + young, 50, 50);


text("adults = " + adults, 50, 100);


text("dead = " + dead, 50, 150);


text("fuel = " + fuel, 50, 200);


text("water = " + water, 50, 250);


text("animals = " + animals, 50, 300);


text("plants = " + plants, 50, 350);


if(counter%birthCount == 0) {
//trigger "birth" transition



adults--;



young = young + 2;


}


if(counter%2 == 0) {
//trigger "renew animals" transition



water--;



plants--;



animals--;



animals = animals + 2;


}


if(counter%animalCount == 0) {


//trigger "renew plants" and "growth" transitions



//renew plants



water--;



plants--;



plants = plants + 2;



//growth



fuel--;



water--;



animals--;



plants--;



young--;



adults++;


}


if(counter%3 == 0) {


//trigger "death" transition



adults--;



dead++;


}


if(counter%4 == 0) {


//trigger "renew water" transition



water--;



water = water + 4;


}


//check mouse position


counter++;

}
}
Re: Text staying on screen?
Reply #1 - Dec 2nd, 2008, 5:03am
 
Yes you did. Smiley
Every time the program runs draw, it does it on top of what was there before. So you have to clear the screen each time.
Put this at the beginning of the draw function:
background(0); // For a black background.
or
background(...some color...);
Page Index Toggle Pages: 1