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

2015/9/26

Removing all Subclasses of an Actor from another Actor When Touching

davis25811 davis25811

2015/9/26

#
I'm working on a project involving a Dog eating Bones. Dog and Bone are both subclasses of Actor. Within the Bone class I have 3 subclasses called "RedBone", "PurpleBone", & "GreenBone". Visual representation: Actor |> Dog |> Bone |> RedBone |> PurpleBone |> GreenBone Basically, what I'm trying to do is remove the bone when the dog is touching a bone, no matter what color it is. This code will remove a Bone but it won't remove any of the colored subclasses. How could I apply this code so that it applies to all of the Bone colored subclasses.
if (isTouching(Bone.class))
        {
            removeTouching(Bone.class);
        }
danpost danpost

2015/9/26

#
If you have empty act methods in the 3 subclasses of the Bone class, you can just remove them. If not, you need to show the act method of the Bone class and at least one of its subclasses (I will presume that all 3 subclasses have similar act methods).
davmac davmac

2015/9/27

#
The code you have will (or at least should) remove any touching instance of Bone including instances of its subclasses (RedBone etc). Perhaps post more of your code (or even upload your scenario) so we can see where this has gone wrong.
You need to login to post a reply.