This site requires JavaScript, please enable it in your browser!
Greenfoot back
BlueHand
BlueHand wrote ...

2021/2/7

Two balls disappearing after collision

BlueHand BlueHand

2021/2/7

#
I only have a counter class, instructions class, and balls class. The balls bounce off the walls and when they hit each other, they are both supposed to disappear. I can make one of them disappear with /** * canSee - Return true if we can see an object of class right where we are. * False if there is no such object here. */ public boolean canSee(Class className) { Actor actor = getOneObjectAtOffset(0,0,className); return actor != null; } /** * hit - Try to hit an object of Class. * Only successful if there's such an object where we currently are. Otherwise it won't work */ public void hit(Class className) { Actor actor = getOneObjectAtOffset(0,0,className); if (actor != null) { getWorld().removeObject(actor); } } but I can't make the other one disappear. What can I do?
danpost danpost

2021/2/7

#
The canSee and hit , which is equivalent to eat, methods are obsolete. They have been replaced by the Actor class methods, isTouching and removeTouching:
if (isTouching(Ball.class))
{
    removeTouching(Ball.class);
    getWorld().removeObject(this);
    return;
}
You need to login to post a reply.