views:

38

answers:

1

I have a ball based on a component and I've thought that using the isShowing() method would do the trick but after my ball leaves the container, (Pong game) the isShowing() method still returns true.

So does the isShowing() method check if the component is still in the container's... bounds? Or just if it is visible and the container is also visible.

...and how do I check if the component has left the container other than doing... ball.getX()+width() < container.getWidth() (sadly only for the left side, but just an example)

+3  A: 

Well, you do ball.getX()+width() < container.getWidth()...
That's the classical way.

Now, you can also use contains, for example.

PhiLho
Oh sweet, didn't know that that existed, I've been using intersects() all the while.Thank you.Oh and just wondering... is it actually more EFFICIENT as in computational processing terms to use X < width instead of using a rectangle and doing contains()?
Dois
Oh and sorry, incase someone is referring to this for collision algorithms or whatever... The left would be whateverObject.getX()+whateverObject.getWidth() < container.getX(). For the right it would be whateverObject.getX() > container.getWidth(). Just incase I confused anyone
Dois
Since you don't create objects, I think they would be roughly the same in term of speed/memory. Using contains is cleaner, in terms of readability.
PhiLho