We are about to switch to a new forum software. Until then we have removed the registration on this forum.
your processing sketch is fabulous, your line count is in the hundreds, you have split your sketch to multiple files, and now you probably have one or more of the following problems:
one solution is wrap every file in a class. preferably with the same name as the file.
(this is a followup to: https://forum.processing.org/two/discussion/23442/how-processing-handles-multipe-source-files)
demonstration:
catmousegame/catmousegame.pde
Game game;
void setup() {
size(400, 400);
game = new Game();
}
void draw() {
background(0);
game.frame();
game.draw();
}
void keyPressed() {
}
catmousegame/game.pde
class Game {
Cat cat;
Mouse mouse;
Game() {
cat = new Cat();
mouse = new Mouse();
}
boolean catonmouse() {
return false;
}
void newmouse() {
}
void frame() {
cat.move();
mouse.move();
if (catonmouse()) {
cat.eatmouse(mouse);
newmouse();
}
}
void draw() {
cat.draw();
mouse.draw();
}
}
catmousegame/cat.pde
class Cat {
int catx;
int caty;
int mouseeaten;
Cat() {
}
void move() {
}
void eatmouse(Mouse mouse) {
}
void draw() {
}
}
catmousegame/mouse.pde
class Mouse {
int mousex;
int mousey;
Mouse() {
}
void move() {
}
void draw() {
}
}
the "compiled" java file:
import processing.core.*;
// bunch of imports
public class catmousegame extends PApplet {
Game game;
public void setup() {
game = new Game();
}
public void draw() {
background(0);
game.frame();
game.draw();
}
public void keyPressed() {
}
class Cat {
int catx;
int caty;
int mouseeaten;
Cat() {
}
public void move() {
}
public void eatmouse(Mouse mouse) {
}
public void draw() {
}
}
class Game {
Cat cat;
Mouse mouse;
Game() {
cat = new Cat();
mouse = new Mouse();
}
public boolean catonmouse() {
return false;
}
public void newmouse() {
}
public void frame() {
cat.move();
mouse.move();
if (catonmouse()) {
cat.eatmouse(mouse);
newmouse();
}
}
public void draw() {
cat.draw();
mouse.draw();
}
}
class Mouse {
int mousex;
int mousey;
Mouse() {
}
public void move() {
}
public void draw() {
}
}
public void settings() { size(400, 400); }
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "catmousegame" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
things of note:
setup()
and draw()
functions must to be top level.the advantage of classes:
the disadvantage:
more notes: