# Issues with setImage and pause for projectiles

**URL:** <https://forum.makecode.com/t/issues-with-setimage-and-pause-for-projectiles/43882>\
**Category:** Help\
**Created:** [May 7, 2026, 9:29pm UTC](https://forum.makecode.com/t/issues-with-setimage-and-pause-for-projectiles/43882 "2026-05-07T21:29:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pumpkinwearingsocks](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/pumpkinwearingsocks/32/19923_2.png) [@pumpkinwearingsocks](https://forum.makecode.com/u/pumpkinwearingsocks)\
**Post date:** [May 7, 2026, 9:29pm UTC](https://forum.makecode.com/t/issues-with-setimage-and-pause-for-projectiles/43882/1 "2026-05-07T21:29:10Z")

</div>

So in a fighting game project, I have code that kind of looks like this for a type of projectile:

```javascript
scene.onHitWall(SpriteKind.Projectile, function (sprite, location) {
    animation.stopAnimation(animation.AnimationTypes.All, sprite)
    sprite.ay == 0
    sprite.vy == 0
    sprite.vx == 0
    sprite.setVelocity(0, 0)
    pause(500) //or really any amount of time
    sprite.setImage(assets.image`yoshieggbreak`)
        
    }
})

```

What’s supposed to happen is when the projectile hits a wall, it stops, switches to a different image (e.g. exploding or broken), pauses a bit to show the image, then after time has passed destroy itself.

What ends up happening though is the projectile hits a wall, stops, the entire game lags for a bit, then the projectile is destroyed without ever displaying the image.

Can you help me figure this out and find a solution?

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 8, 2026, 6:33pm UTC](https://forum.makecode.com/t/issues-with-setimage-and-pause-for-projectiles/43882/2 "2026-05-08T18:33:39Z")

</div>

When you pause inside a function such as onHitWall, it pauses _everything_. This is because the function is not internally running inside a control.runInParallel function. This is the function that allows other code to run while the pause function is running. To fix this, you can run the code inside the control.runInParallel function, but this will cause issues as this function will be set off every frame that your sprite is hitting the wall. Instead, you can set the image and then set the sprite’s “lifespan” variable. This will automatically destroy the sprite after the specified number of milliseconds. This way there is no pausing needed inside the onHitWall function at all!

---

<div class="post-metadata">

**Author:** ![NeverStopTheCoder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neverstopthecoder/32/21194_2.png) [@NeverStopTheCoder](https://forum.makecode.com/u/NeverStopTheCoder)\
**Post date:** [May 8, 2026, 10:47pm UTC](https://forum.makecode.com/t/issues-with-setimage-and-pause-for-projectiles/43882/3 "2026-05-08T22:47:42Z")

</div>

use the timer extension use the after 500 do and put that at the top like this

```auto
scene.onHitWall(SpriteKind.Projectile, function (sprite, location) {
timer.after(500, function () {
 sprite.setImage(assets.image`yoshieggbreak`)
 })
    animation.stopAnimation(animation.AnimationTypes.All, sprite)
    sprite.ay == 0
    sprite.vy == 0
    sprite.vx == 0
    sprite.setVelocity(0, 0)    
    }
})

```
