We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I've created an object called Cloud that consists of may circles. The Cloud is animated and moves out of the screen at some point. I want to check if it has left the screen completely so I can remove it from my arrayList. But I don't know how to get to the width and x values of the whole Cloud object. Is there a way to do this?
Thanks very much in advance for your help, best, Danielle.
Comments
Have you created a class for the Cloud? If so could you show the code for it?
Hmm, something went wrong with the formatting, hope you can still understand?
I have corrected the code formatting for you in future highlight the code and press Ctrl+O (that is the letter O, in the previous forum it was K and hopefully it will go back to that sometime)
Just to clarify
wholeCloud
is an array of the circle centres, andrVals
is the radius of each circle it that correct?absolutely correct
To be a bit more precise, a PVector with x and y values for the circles
To be a bit more precise, a PVector with x and y values for the circles
There are several ways that you could program a solution. The code below is one such way, it simply tests to see if a part of the cloud fits inside a rectangle, if it does then the cloud must be visible and the testing stops.
Add this method to your class. I haven't tested it but I believe it is correct. Simply call the method with the position of the rectangle you are interested in.
BTW I made a mistake in the code above I have changed it :)
Wow, thanks very much, that's very elegant! So you constantly check the whole PVector array and add the radius to the location to see if it's completely left view. Great, works like a charm.
The advantage of doing it that way is that not only can the clouds move but also the circles can move within the cloud if you want. This is a much more flexible approach than calculating the cloud 'limits'.