Oarsman05
YaBB Newbies
Offline
Posts: 1
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++; } }