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 & HelpPrograms › Text fade in problem
Page Index Toggle Pages: 1
Text fade in problem (Read 662 times)
Text fade in problem
Mar 7th, 2007, 7:51pm
 
Hello everyone,
Hopefulle someone can find the problem with my applet lol.
We're suppose to see a new line of text (external file) appear each time the user click on the screen.
I wanted to use a "fade-in" so the text would appear gradually. I tried using the alpha channel but it doesn't seem to work for some reason:
The text appear in one shot, without the alpha.

Code:


//===================================================
//Global variables
//===================================================
PFont f; // variable for font
String[] textfile; // will contain contents of external file
int text_index = 0; // tracks location in the textfile array
int xPosition = 20; // position of the line of text on the screen
int yPosition = 50; //position of the line of text on the screen
//---------------------------------------------------
//setup
//---------------------------------------------------
void setup(){
size(600, 600) ;
background(0) ;
frameRate(10) ;
fill(0);
smooth();
f = loadFont("BlackadderITC-Regular-30.vlw"); //load font
textFont(f, 30); // set the display font
textfile = loadStrings("kaelar.txt"); // load the contents of the external file into the string array
}



//===================================================
//FUNCTIONS
//===================================================
void sprayText(){ // writes a line of text at x and y position

if (text_index < textfile.length) { // are we past the end of the string array?


for(int i=0; i<255; i++){
fill(255,i); // The alpha of this fill doesn't seem to be working?
text(textfile[text_index], xPosition, yPosition);
//background(100,10); **edit**oops this isn't suppose to be here :P
}
text_index++;
xPosition = xPosition+40;
yPosition = yPosition+40;
}
else{
text_index = 0;
} // yes...reset index of string array to beginning

}
//===================================================
void mousePressed(){
sprayText();
}

//===================================================
//DISPLAY
//===================================================
void draw(){
}


thank you in advance
Re: Text fade in problem
Reply #1 - Mar 7th, 2007, 8:04pm
 
Nothing gets drawn to the screen, until all functions have finished each frame, so the textSpray() function runs until it's finished, and *then* the screen updates.

So you don't see the fade in, since all the 255 draws happen *before* anything appears on screen.

To get the effect you want, you'll have to find a way to only do one part of the draw each frame.
Re: Text fade in problem
Reply #2 - Mar 7th, 2007, 8:20pm
 
That would explain it. Then I shall try something else Smiley

thank you for your help
Page Index Toggle Pages: 1