Don't know how to activate method

I am a beginner at Java

    public void drawScore() {
        scoreFont = createFont("Bauhaus 93", 26, true);
        textFont(scoreFont);
        fill(255,255,255);
        textAlign(CENTER);
        text("Score: " + score, width - 90, 40);
    }

I don’t know how to make it so that it actually functions when I run the program.

1 Like

https://processing.org/tutorials/

Java calls them methods and Processing calls them functions:
https://processing.org/examples/functions.html

1 Like

In draw() say:

drawScore();

this calls / runs the function you defined above

1 Like

actually, to save processor time, it’s wise to initialize the font in setup() (which runs only once, whereas draw() runs on and on 60 times per second (and so does drawScore() when you call it from draw()))

  • So I did a bit of a re-write here

Chrisir


PFont scoreFont;
int score=0; 

void setup() {
  size (1400, 800);
  background(0);

  scoreFont = createFont("Bauhaus 93", 26, true);
}

void draw() {
  background(0); 
  drawScore();
}

void drawScore() {
  textFont(scoreFont);
  fill(255, 255, 255);
  textAlign(CENTER);
  text("Score: " + score, 
    width - 90, 40);
}
//
1 Like