Hello, hopefully someone can help me. One of my students created a tennis game and the game begins fine with the ball (a sprite) “moving ten pixels north”.
When the ball “touches” the player (another sprite) the ball begins bouncing 25 pixels south".
When the ball "touches: the other player (different sprite) the ball begins bouncing north again.
At this point however, the next time the ball touches the player sprite, it should bounce back south again, but it is not bouncing back, resulting in game over.
Hi Mr. Marsman,
The issue here is that a sprite can actually have multiple behaviors at once. Beginning one behavior doesn’t automatically stop the others.
At the start of the game, the ball is moving north or south which means up by 10 pixels.
After it hits the top player, the ball is moving north or south and bouncing south which means it’s moving up by 10 pixels and down by 25 pixels at the same time. What we see is the ball moving down.
Finally after hitting the bottom player, the ball has all 3 behaviors. It’s going to move up by 10, down by 25, and up by 25. We’ll see the ball just keep moving up forever (until game over).
A solution to this problem is to make sure to stop any current behaviors before starting a new one. An example of this would be the following: