We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm ultimately trying to click a particle and be able to drag it around the screen.
I'm building off the SimpleParticleSystem example.
Things likevoid mouseDragged()
can't be carried out in classes. So one must call them from the main sketch, which is simple enough... except that I'm working with a particle system (array list) composed of 2 classes (1 describes the particle group, 1 describes the particle itself), which is creating lots of problems for me.
I found this thread describing how to implement void mousePressed in classes, but the example answer that apparently worked for the asker did not work with my particles.
I'm able to freeze and capture the exact coordinates of a moving particle on hover, and even identify it's sequence in the array, but when it comes to using variables from one class in the other, I just end up getting static vs non-static field errors or null pointer exceptions.
It'd take me probably an hour to sort out my code to present my specific problems (and I can't really think anymore today :P), so I'd just like to know:
Is it even possible to have such interaction with a particle system; to be able to single a particle out (i.e. on click) and manipulate it independently (i.e. drag it around)?
Has anyone here done this before?
Does it require "hacking" around the particle system somehow (i.e. creating a new object on top of the particle and manipulating that instead of the particle itself)?
Thanks in advance for any feedback, hopefully this will help me move forward so I can come up with a more sensible question.
Answers
That link seems to belong to a far away epoch!
Nevertheless, I'd still go w/ 1 mouseDragged() approach for performance reasons!
If you got its coordinates + its dimensions, just measure them against mouseX & mouseY.
Yeay, of course it can be done. I suggest an approach using mousePressed() or mouseDragged() and mouseReleased(). Basically you have a global int selectedparticle, which is set to -1. On mousePressed() or mouseDragged() (whichever suits best), if no particle has been selected, you go over all the particles. When you are within distance of one (mouseOver), you select that one and break out of the for loop. On mouseDragged(), if one is selected (aka int is >-1), you drag only this selected particle. On mouseReleased(), the int is set to -1 again. Something like that should work! :)
Perhaps that should mean the List<Particle>'s index? /:)
Sorry, I forgot to mention that explicitly. Indeed, like @GoToLoop said, the -1 I'm talking about is the index of the particle in the List/ArrayList/Array you are storing them in.