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

2018/4/6

Newtons Lab book assignment 8.42

arutledge20 arutledge20

2018/4/6

#
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?
danpost danpost

2018/4/6

#
arutledge20 wrote...
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?
Nothing is wrong with the code shown (as far as what can be determined by what was given). What is wrong is probably in code that you have not shown (yet).
You need to login to post a reply.