Glitch when triggering sound on projectile creation

Hi, I’m helping teach Arcade.Makecode for TEALS and student found an issue. We create a game with a movable player sprite, set the A button to create projectiles from the student, and then set an “on created sprite of type projectile” to play a “pew pew” song. With this combination the projectiles momentarily appear in the center of the screen and then relocate to the correct location (where the player sprite is).

2 Likes

This one is somewhat expected behavior; we run the ‘on sprite created’ code synchronously / before we ‘finish’ making the sprite and continue from wherever the sprite is made, because we need to be able to use it to make changes that affect the code that follows (e.g. changing the image and letting the code after see the new image). In this case, to get the behavior you want, you can change the dropdown in the play sound block so that it does not stop the rest of the code while the sound is running by changing it from until done to in background:

to-in-background

and more complicated examples (e.g. if you need to have a pause block for some reason? haven’t run into any myself) can be handled by using the timers extension with the separately do block

(We could consider moving the projectile logic so that the position / velocity are set before the on create runs, but that’d also have some weird behavior – e.g. if the image was changed, the projectile would be positioned incorrectly. For that reason I’d lean towards keeping as is.)

3 Likes

Thanks, that does fix the behavior. I know there’s a lot going on behind the scenes of our makecode env. Appreciate the quick response!

1 Like