My assignment is to make code so that whenever a planet in the Newton's Lab scenario moves over an obstacle, the obstacle toggles into a mode where it flashes between two images, and plays a sound periodically. My code for most of this works, but for some reason the code to toggle between modes does not. Here it is:
if (touched && isTouching(Body.class))
{
touched = false;
}
if (!touched && isTouching(Body.class))
{
touched = true;
}
Touched is my boolean. For some reason, planets that touch it do not toggle it. This code is in a void with my other code that cycles through images and plays sounds. When I move the code to be in the act method, it will change, but only if a body was placed into the world on top of it. After the first change from that body, it doesn't change ever again. What is wrong with this code?

