We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I needed to learn to use PGraphics to achieve what I wanted in my code - scrolling text across the screen and the ability to "graffiti" it too".
However, since re-writing, my font, size, boldness etc won't change!
In my non-PGraphics code, I used
font = createFont("CourierNewPS-BoldMT-48", 44, true);
However, in my new code, it doesn't seem to use the values that 'font' has.
My new code is (sorry for the length - I have no idea where the font code should be)
import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
// import necessary libraries to play sound effect
String[] tickerText =
{
"children were some of the greatest victims", "I was a child soldier",
// ....
};
Minim minim;
AudioPlayer sound1; // variable name
AudioPlayer sound2;
PGraphics pg;
PFont font; //declare PFont object called font
PImage background;
float x; // location of text on x axis
int index = 0;
void setup() {
size(615, 762, P2D);
font = createFont("CourierNewPS-BoldMT-48", 44, true);
background = loadImage ("background_Text_Image.JPG"); // load background image
minim = new Minim(this); //define construction
sound1 = minim.loadFile("Children_Playing_Sound.mp3");
sound1.loop(); // is looped
pg = createGraphics(width, height, P2D);
pg.beginDraw();
pg.background(background); // draw background as imported image
pg.endDraw();
font = createFont("CourierNewPS-BoldMT-48", 44, true);
x = 0; // the int x is used as the entry point for the text scrolling in
}
void draw() {
if (mousePressed) { //function activated by mouse
pg.beginDraw();
pg.line(mouseX, mouseY, pmouseX, pmouseY);
pg.stroke(random(255), random(255), random(255)); // stroke changed to random RBG values, each with a max of 255
pg.strokeWeight (random(4, 8)); // random stroke weight, with a min of 4 and max of 8 pixels
pg.endDraw();
}
background( pg.get() );
textFont(font);
fill(255,0,0); //sets colour of font, red
text(tickerText[index], x, height/2); //location of text on x axis - in this case mid-way
x = x - 1;
float w = textWidth(tickerText[index]); // calculates the width of the text string - necessary for knowing when the text leaves the screen
if (x < -w) { // when x moves completely off the screen new text appears
x = width;
index = (index + 1) % tickerText.length;
}
}
Thank you in advance
Answers
Each PGraphics instance has its own properties, including its own active PFont.
If you wanna use some PFont in some specific PGraphics, you need to apply textFont() there!