Hello!
I am creating a game, where raindrops fall from the sky. At the ground there is a bucket, if the bucket collects the raindrop, player gets points, otherwise players loses a life. :)
I have two problems and both are related to removing objects. The first problem is removing objects when they fall to the ground. I wrote code for it:
If every raindrop falls to the ground - everything is fine. But if any of the raindrops are collected after a bit I get an error message: Actor not in world. An attempt was made to use the actor's location while it is not in the world.
I think I realize the cause of problem - the actor gets picked up(removed) by the bucket and my code checks for every raindrop, including the removed one. How should I change my code so that it only checks those which are still in the World?
The other problem is with the bucket, the code is here:
The problem is, that bucket should only collect raindrops when the raindrops get picked by the ]upper part of the bucket, but with this code I can pick the raindrop even if they are to the side of the bucket. :)
Thank you for help!
if ( this.getY() == 590) { getWorld().removeObject(this); Greenfoot.playSound("RainDrop.wav"); }
if (isTouching(Bucket.class)) { getWorld().removeObject(this); }