I am trying to write a simple ball game, and there are several turns (i.e. the ball lives). The ball dies when it passes the bottom of the screen. That I am still working, but it seems, cannot be the right way:
if (ball.getY() > bottomOfScreen) { ball.die(); remove(ball); }
The die () method basically gradually reduces the color of the ball (dark_gray → pause (50) → light_gray → pause (50)), but actually does nothing useful.
Remove (), obviously, get rid of the ball from the screen, what I want. It seems to me that this remove () is part of the Ball die () method, in contrast to the fact that it is a separate method call in the main program, but I'm not sure how to do it?
Can an object delete itself? And, if possible, is objective suicide better than killing an object from a philosophical / methodological point of view?
Thanks!
Alicja z
source share