I have been working on a processing.js demo in which bodies orbit a central point. I am attempting to add a listener for input that checks if the s
key is pressed each update and if so calls a method to reduce the size of each bodies' orbit by a specified factor.
The example is here on jsfiddle.
Essentially I have placed code in the update() method to listen for a key press:
void update()
{
//detect input
if(keyPressed)
{
debugger; //debug
if(key == 's' || key == 'S')
{
//shrink orbit
ShrinkOrbit(planets,.9);
}
}
}
Which calls the ShrinkOrbit(ArrayList <OrbitingBody> orbs, float reductionFactor)
method:
/*
* Reduces size of orbit for specified group of orbiting bodies
*/
void ShrinkOrbit(ArrayList<OrbitalBody> orbs, float reductionFactor)
{
for(OrbitalBody b:orbs)
{
b.x *= reductionFactor;
b.y *= reductionFactor
}
}
However, currently not only does the debug breakpoint not trigger, but I see some errors cropping up in the chrome developer tools:
Uncaught SyntaxError: Unexpected reserved word
Uncaught TypeError: Cannot read property 'reason' of null Actions.js:333
(anonymous function) Actions.js:333
(anonymous function) moo-clientcide-1.3.js:212
Array.implement.each moo-clientcide-1.3.js:329
(anonymous function) moo-clientcide-1.3.js:212
Class.JSLintValidate Actions.js:330
wrapper.extend.$owner moo-clientcide-1.3.js:3798
Class.jsLint Actions.js:277
wrapper.extend.$owner moo-clientcide-1.3.js:3798
(anonymous function) moo-clientcide-1.3.js:1027
defn
Was I wrong to assume that update()
is a global method, something equivalent of setup
that can be called in any sketch? I had seen it used as such in another functioning jsFiddle, which is from where I drew my conclusion. I am targeting Processing.js 1.4.1 if that is any help.