We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I saw this code online at http://learningprocessing.com/examples/chp17/example-17-06-textbreakingup and I'm trying to test and understand it out on my own, however the sketch won't run because of the error "The class "Letter" does not exist". Also, is there a way to change the font color when the mouse is pressed?
// Example 17-6: Text breaking up
PFont f;
String message = "click mouse to shake it up";
// An array of Letter objects
Letter[] letters;
void setup() {
size(480, 270);
// Load the font
f = createFont("Arial", 20);
textFont(f);
// Create the array the same size as the String
letters = new Letter[message.length()];
// Initialize Letters at the correct x location
int x = 125;
for (int i = 0; i < message.length (); i ++ ) {
// Letter objects are initialized with their location within the String as well as what character they should display.
letters[i] = new Letter(x, 140, message.charAt(i));
x += textWidth(message.charAt(i));
}
}
void draw() {
background(255);
for (int i = 0; i < letters.length; i ++ ) {
// Display all letters
letters[i].display();
// If the mouse is pressed the letters shake
// If not, they return to their original location
if (mousePressed) {
letters[i].shake();
} else {
letters[i].home();
}
}
}
I tried adding 'class Letter', but it only creates another error on "ClassBody". I need help. :(
Answers
http://LearningProcessing.com/code/LearningProcessing/chp17_strings/example_17_06_textbreakingup/Letter.pde
@GoToLoop Nothing shows up when I run that code :( The error is "The type Letter is never used locally"
Pay attention the sketch "example-17-06-textbreakingup" on the link you've posted got 2 ".pde" tabs:
You need to join your code above and the class from the link gotoloop posted and then run the merged sketch
From: https://Processing.org/tutorials/overview/
@GoToLoop @Chrisir I see! I didn't realize that I missed that other tab hehe. Thank you so much for your help :) ^:)^
;-)