How to pass an object as an argument to the function mousePressed() in Processing

Samuel John :

running println(game.gameOn) for the function below still output false.

  1. why this ambiguity?
  2. what's the solution?

Maybe I can't pass in an object as a parameter to the function mousePressed()

void mousePressed(Game game) {
    game.gameOn = false;
}
Rabbid76 :

You can't pass an object to mousePressed(). mousePressed() is an event callback and called by the system during the event handling.

The one and only possible argument to mousePressed is the event argument of type MouseEvent.e.g.:

void mousePressed(MouseEvent event) {
   println("EVENT " + event);
}

If you want to access an object in mousePressed, then you've to use a global variable. e.g.:

Game game = new Game();

void mousePressed() {
   game.gameOn = false;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=327778&siteId=1