A student would like to know when a car sprite is touching a road , which will be a sprite on top of the background (bg). I thought a test for car.istouching.bg might be false if the car were touching the road sprite on top of the background. I wrote some test code to see if this would work. I put a car and some road sprites on top of the bg sprite and I made the car shake as long as car.istouching.bg is true.
Unfortunately, the car shakes the whole time, even when it is over the road.
Does anyone have any ideas on how to do this? The difficulty is that she wants to have a path that is not straight across the screen.
One idea I had was for her to create the road using multiple sprites that together form the road. Then she could have multiple if statements to determine if the car istouching road OR road1 OR road2, etc. This works, but it could get unwieldy when there are more than a few sprites that make up the road.
Update: Just figuerd out that putting all the road sprites into a group would work…
The code I linked to here includes all 3 tests along with comments to explain.
Link to the test code I made: Game Lab - Code.org
Thank you,
John