We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have text which I'd like to display on random X-Y co-ords and fade out. This text is randomly pulled from a string array. This words correctly using an if loop for decrementing alpha over time.
The simple code for the string "this text will be instructions" takes on the 'attributes' though and instead of simply displaying for x milliseconds at set co-ords, also fades and is positioned randomly. I know the problem is with my use of loops but can't for the life of me see where / why.
Thank you in advance.
if (millis() < 5000) {
text("this text will be instructions",width/3,height/3);
}
else if (millis() - lastTime >= timeToDisplay) // if statement to allow text to fade in and out.
{
count = int(random(myArray.length)); // use length of array to get word random within its length (size)
textSize(random(35, 50)); // random sized text - set min / max values
randomX = random(100, 500); // random placement of text
randomY = random(100, 500);
alphaSetting = 255; // set alpha setting of 255 = fully 'there'
lastTime = millis();
}
fill(white, alphaSetting); // white text
text(myArray[count], randomX, randomY); // chose word from myArray - an array of the words from
alphaSetting -= a; // fade out of text by decrememtning alpha
cam.endHUD();
Answers
you don't post the entire sketch / a mcve
so it's hard for us because we have to rewrite it all
maybe it doesn't work because you don't have that:
Thank you @chrisir for your reply. When I run your code, I get the random string from myArray but don't see "this text will be instructions" anywhere.
What is an mcve?
I have background in my code. Here it is in full.
the code you shared did not seem to compile so i did some minor changes and it worked, plus you were missing some brackets so im not sure if you where having this issues because the code you posted as is or if you alter the code prior to posting
also i noticed that at the vary end you have a function that i do not see being used at all though out your draw or setup so was wondering why the implementation ?>