Loading...
Logo
Processing Forum
physics.removeBehaviour() lets me specify a behaviour but how do i reference all behaviours current in the sketch.

I have lots of Attraction Behaviours being created causing the particles to be attracted no problem but i want a keypress to remove all so that the particles will have no attraction and just drop.

Im struggling to figure the syntax using the javadocs.




Replies(7)

You can just remove all behaviors...
Copy code
  1.   for (int i=physics.behaviors.size()-1; i>=0; i--) {
  2.     physics.removeBehavior(physics.behaviors.get(i));
  3.   }

physics.behaviours.size cannot be resolved or is not a field.
Make sure to copy-paste or type accurately. Behaviors is without u and size is with brackets ().
Here's an slightly different form from above:  
for (int i=physics.behaviors.size(); i!=0; 
physics.removeBehavior( physics.behaviors.get(--i) ));

Or even easier:
Copy code
  1. physics.behaviors.clear();
As a general tip for making more sense of the toxiclibs API, I really recommend reading up on the Java Collections API, which is heavily used throughout the library and familiarity with it will make your life just so much easier...

http://postspectacular.com | http://toxiclibs.org