# Sprites across different tilemaps

**URL:** <https://forum.makecode.com/t/sprites-across-different-tilemaps/23158>\
**Category:** Help\
**Created:** [October 9, 2023, 4:53pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158 "2023-10-09T16:53:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![teresitacuesta](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/teresitacuesta/32/10737_2.png) [@teresitacuesta](https://forum.makecode.com/u/teresitacuesta)\
**Post date:** [October 9, 2023, 4:53pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158/1 "2023-10-09T16:53:48Z")

</div>

I’m not a coder, so I need lots of help to be able to help my students. They are developing a three-level game. They use “on sprite overlaps this tile, set new tilemap” to go to the next level. The problem is that projectiles from previous tilemaps keep spawning and new projectiles don’t spawn.

---

<div class="post-metadata">

**Author:** ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)\
**Post date:** [October 9, 2023, 9:57pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158/2 "2023-10-09T21:57:04Z")

</div>

Please provide a share link of this particular game here so it is possible for a forum member to help.

---

<div class="post-metadata">

**Author:** ![teresitacuesta](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/teresitacuesta/32/10737_2.png) [@teresitacuesta](https://forum.makecode.com/u/teresitacuesta)\
**Post date:** [October 10, 2023, 7:18pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158/3 "2023-10-10T19:18:04Z")

</div>

Thanks! Here is a mock up:

> **[projectiles](https://arcade.makecode.com/S83745-37397-07913-76276)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I understand that the donuts keep appearing because they are in a forever loop but I don’t know how to stop it. I also understand that the hamburger appears only once, on overlap, and would need to be in some kind of forever loop.  
In both cases, the question is, how do I code “forever while on this tilemap.” I have tried different if, thens, but with no success.  
Thank you so so much for helping out a teacher!

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [October 10, 2023, 8:30pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158/4 "2023-10-10T20:30:40Z")

</div>

You can use a level variable to control which sprites spawn, and when they spawn.

> **[projectiles](https://arcade.makecode.com/S04442-90972-50928-20815)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

 ![code](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/33ecd5ae8c5bf58e85ffb56660720b238146e455.png)  
I hope this helps! 🙂

---

<div class="post-metadata">

**Author:** ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)\
**Post date:** [October 10, 2023, 8:31pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158/5 "2023-10-10T20:31:37Z")

</div>

> [@teresitacuesta](#):
>
> In both cases, the question is, how do I code “forever while on this tilemap.”

I did not figure out how to compare the image of the current tilemap directly, but one way is to set a state variable for each tilmap and check this for setting the correct projectile in the loop:

> [@teresitacuesta](#):
>
> I don’t know how to stop it

Remove all sprites from current tilemap when entering the new tilemap by using e.g. the _sprites.destroyAllSpritesOfKind(SpriteKind.Projectile)_ block.

> **[projectiles](https://arcade.makecode.com/47041-76685-62765-00090)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)\
**Post date:** [October 10, 2023, 8:43pm UTC](https://forum.makecode.com/t/sprites-across-different-tilemaps/23158/6 "2023-10-10T20:43:39Z")

</div>

Hahaha, @Blobbey!

You beat me by just one small minute with almost exactly the same solution!  
(But we are talking @MakeCode moderator approval timestamps, so not sure if you really were first…) 😉

Anyhow, this is not a competition.

_Does anyone know how to do stuff like this without using state variables?_

I am tired of fighting with/keeping track of state variables all over the place all the time…
