We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, i'm new to processing and i'm still figuring it out!
I want to click a specific item on screen and remove it from an ArrayList. So far I can remove only the 0th item from the list. This is obvious since i've something like this:
if (mouseButton == RIGHT) {
if(bubbles.size() > 1) {
if(mouseX> ballX-radius*2 && mouseX < ballX+radius
&& mouseY> ballY-radius && mouseY < ballY+radius){
bubbles.remove(0); ////HERE BE PROBLEMS
}
I cannot understand how to select whatever object from the ArrayList
I've got other problems in the code, but if you guys help me out with the remove problem i should be able to get the other parts right.
here is the complete code.
[see below]
Answers
ctrl-t in the editor will indent your code nicely and make the code structure easier to see.
here is the code indented with ctrl+t! sorry for the bad formatting
It shouldn't be to hard to fix. Loop, using a for statement and then to check for nearness by calling bubbles.get(i).xActually, I see that you are using a method inside the class to delete itself from a structure outside of the class you have. I suggest moving that outside, as getting information about where a class is in an ArrayList might be messy. If you use something like
or
Then, inside of that, you can loop through the elements with a for(int i = 0; i<bubbles.size();...
And then use a new class specific function
bubbles.get(i).clickedInside(mouseX,mouseY);
to access the ith element of the ArrayList and call a function that returns true or false depending on whether you clicked inside the circle or not.
After that, if the function returns something signifying that you did click in the ith circle, then
should do the trick by removing the ith element of the ArrayList, the one you clicked. (If you used a .clickedInside(mouseX,mouseY); that returns a boolean, you can stick it inside the parenthesis following an if statement and put the bubbles.remove(i); in the curly braces.)