# Check if sprite exists

**URL:** <https://forum.makecode.com/t/check-if-sprite-exists/10823>\
**Category:** Arcade\
**Created:** [November 10, 2021, 4:39pm UTC](https://forum.makecode.com/t/check-if-sprite-exists/10823 "2021-11-10T16:39:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fmvmedeiros](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/fmvmedeiros/32/5076_2.png) [@Fmvmedeiros](https://forum.makecode.com/u/Fmvmedeiros)\
**Post date:** [November 10, 2021, 4:39pm UTC](https://forum.makecode.com/t/check-if-sprite-exists/10823/1 "2021-11-10T16:39:18Z")

</div>

Hello,  
How can I check if a sprite exists on the screen?  
I want to make a shooter game but with a limit to the speed the shots can be fired.  
I thougt about using logic to see if the the sprite exists, so only one shoot can be fired untill it hits a target or it goes off screen but I dont know of a way to check this.  
Anyone have some idea how to make this? Or some other sollution?  
Thank you.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [November 10, 2021, 8:13pm UTC](https://forum.makecode.com/t/check-if-sprite-exists/10823/2 "2021-11-10T20:13:05Z")

</div>

The sprite utils extension ([https://github.com/jwunderl/arcade-sprite-util](https://github.com/jwunderl/arcade-sprite-util)) has a boolean block which checks if a sprite exists and it isn’t destroyed.

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [November 10, 2021, 8:13pm UTC](https://forum.makecode.com/t/check-if-sprite-exists/10823/3 "2021-11-10T20:13:41Z")

</div>

We do this one pretty frequently in shooter games. Great question! Take a look at this code:

 ![arcade-screenshot (1)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/a4a81b7db83023d44a4caef1f2c3c498cbd3c0ec.png)

In the event handler for the **A** button press, a projectile is only created if none exist. You can modify the logic statement to suit your needs, but that’s the idea:

- Get a list of all sprites of a particular type.
- Count them up.
- See if there number on the screen allows us to add another sprite (or whatever action you like).

You could add an `else` clause there and play a sound or something to let the player know that they can’t shoot right now.

This code works because the `set projectile` creates a sprite that automatically destroys itself when it leaves the screen. If you’re not using the `set projectile` block, then that’s OK! Just add another block that sets `auto destroy` to `ON`, right after you create the sprite. You can find that block in the **Sprites** drawer of the toolbox.

---

<div class="post-metadata">

**Author:** ![Fmvmedeiros](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/fmvmedeiros/32/5076_2.png) [@Fmvmedeiros](https://forum.makecode.com/u/Fmvmedeiros)\
**Post date:** [November 11, 2021, 4:50pm UTC](https://forum.makecode.com/t/check-if-sprite-exists/10823/4 "2021-11-11T16:50:03Z")

</div>

Thanks. That is exactly what I need.
