We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I'm trying to replicate http://loop.monolithinteractive.com/ as an exercise.
I have accomplished a few things but I'm stuck on the method that checks circles collisions. I get an IndexOutOfBoundsException in Class ExpandingCircle > void checkCirclesCollisions.
You can find the whole code here: https://dl.dropboxusercontent.com/u/1835810/monolithloop.zip
I can't get around it, please help.
Thank You :)
Answers
Hello, I think you must change your array familly (line 10), to compare easily the tartget with your list circles (line96) I make a litlle change in your code, I don't find the solution but sure the solution is on this way !
Hey Stanlepunk,
thanks for fixing that error.
Honestly I've copied the code for checkCriclesCollisions from Examples > Topics > Motion > BouncyBubbles and I thought that adapting it to my sketch would work. I was wrong.
Any idea on how to check circles collisions? both external and for circles within circles?
Thank You
You must work around this code, specificly the void collide(), if you don't manage next week I have more time to look your code.
Hey Stanlepunk,
I'll try it again.
Thank You :)
Hi Stalepunk,
I've been debugging and I get the right data for .x .y. and .radius with the arraylist, but I cannot get it to do what I need.
halp?
please and thank you
Note about the code of stanlepunk (not 'stale' yet! ) :-)): a Ball should not know about the other balls! It is a bit wasteful for each ball to have a list of all the balls.
Better make them independent and either manage the list of balls at the global level, or wrap it in another class (BallManager for example).
Hi PhiLho,
jfyi: that code is from the Examples > Topics > Motion > BouncyBubbles.
yet I'd love to solve Class ExpandingCircle > void checkCirclesCollisions in mine :P
Some examples in Processing have been integrated from 3rd party sources, and are not perfect in terms of best coding practice, despite their cleverness and nice and correct output... :-)
Sometime I criticize working code because:
I see other things that can be improved, like not checking if a circle hits itself... And, because of the problem I criticized above, all the collisions are checked twice, not good for performance / efficiency: there is a loop on all balls to check for collision, and each ball loops again on all balls, to see if it hits another ball.
Better make a method isColliding(ExpandingBall otherBall) to see if a ball is colliding another, and use that in an external loop.
(Note: I criticize only the code I see here...)
Note also that you can write
ExpandingCircle ec = circles.get(i);
(no need for(ExpandingCircle)
cast) because the ArrayList has a type<ExpandingCircle>
.Alas, just looking at the code, I don't see why you get an array out of bounds exception, I should run it to be sure, but I don't have the time to remove all the extra code (audio) which might not run on my computer.
Use println() with the size of the array list and the index about to be used just before the line throwing the error, to see what is going on.
I've got a very similar example of colliding balls: L-)
http://studio.processingtogether.com/sp/pad/export/ro.91xkuWl51J$Vp/latest
But it doesn't use best practices like @PhiLho said! I've just tweaked it a lil' and published it online! 8-X
Hi PhiLho,
thank you for your precious contributions, I understand and agree with you on everything. I just thought that examples would be good code just because they are in there, that's all.
Leaving the balls example out for good, the out of bound was in my code (first post) but Stalepunk solved it with his correction in his first reply.
Going back to my actual problem, I still don't manage to check collisions between expanding circles. My idea (other than the one I took from Balls) would be to get circles.x, circles.y and circles.radius and have math calculate if the collide (both internally and externally). What do you think?
Thank you and sorry for the lag.