A few ways that I’ve seen students deal with this issue:
- Move the sprite to a new location as soon as they touch
- Use a boolean variable to track if a sprite has been touched
- Use a coutdown/countup variable that gets reset when sprites touch eg:
var countdown = 0;
var score = 0;
draw() {
// If the countdown hasn't finished, keep counting down
if (countdown > 0) {
countdown = countdown - 1;
}
if (sprite1.isTouching(sprite2)) {
// Check if the countdown timer is active before scoring
if (countdown == 0) {
score = score + 1;
// Start the countdown timer to prevent another score
countdown = 10;
}
}
}