I have found that when using OOP with processing.js you must prepend all instance variables with a this.
in order for it to work correctly, especially when such objects are instantiated within an array
or an ArrayList
. You will need to make this modification to all constructors and methods.
For example:
class Route {
ArrayList<Integer> cities;
float distance;
Route(ArrayList CITIES, float DISTANCE) {
this.cities = CITIES;
this.distance = DISTANCE;
}
}
For a live example, check out the .pde linked in the source of my interactive resume.
The modified code will still execute in Processing : Java / Standard Mode but becomes excessively wordy. I usually only make this change if I am porting a project to processing.js or wanting to have a project that works in both Standard / Java and JavaScript (processing.js) modes.