# Spawning Off Screen

**URL:** <https://forum.makecode.com/t/spawning-off-screen/26804>\
**Category:** Help\
**Created:** [February 11, 2024, 9:58pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804 "2024-02-11T21:58:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamal](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jamal](https://forum.makecode.com/u/Jamal)\
**Post date:** [February 11, 2024, 9:58pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/1 "2024-02-11T21:58:55Z")

</div>

I’ve been trying to recreate all of the Super Mario bros and need an answer on making enemies spawn off screen. Every time I run the program the enemies fall into a hole and I don’t want them to spawn until i reach a point in a level.

---

<div class="post-metadata">

**Author:** ![ash6470](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@ash6470](https://forum.makecode.com/u/ash6470)\
**Post date:** [February 12, 2024, 4:42pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/2 "2024-02-12T16:42:52Z")

</div>

For making them spawn at a certain point in the level would something like forever if player x is a certain value spawn the enemies thats just an idea though

---

<div class="post-metadata">

**Author:** ![RobbyZero](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/robbyzero/32/17188_2.png) [@RobbyZero](https://forum.makecode.com/u/RobbyZero)\
**Post date:** [February 12, 2024, 4:43pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/3 "2024-02-12T16:43:12Z")

</div>

You could make invisible tile locations that act as checkpoints and once you reach it spawns it in just remember to name your tile

---

<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:** [February 12, 2024, 4:43pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/4 "2024-02-12T16:43:25Z")

</div>

if you are using code that places an enemy on every tile of a certain kind, you can repeatedly check whether or not that tile is close to your player and only spawn an enemy when they are. Sort of like this:  
Forever:  
For element (value) of (array of all ( enemySpawnerTile) locations):  
If ((value) row) - (tilemap location of (mySprite) \< (40)):  
(Code for summoning the enemy)  
(Place (EmptyTileOrSomething) at (tilemap location of (my enemy))

Sorry for the unreadability of that, but this is (theoretically) the code for checking if a tile is less than 40 blocks to the right of the player and spawning the enemy if it is. (maybe don’t take my word for this I didn’t test it)  
You can modify the code to also check distance upwards and stuff and change the (40) to whatever you want. I hope this makes sense!

---

<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:** [February 12, 2024, 4:44pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/5 "2024-02-12T16:44:36Z")

</div>

I figured I should make a more readable version of that. Also, that code would not work at all I did that math wrong. Here is a better version:

 ![IMG_2652](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c873d1e471d67cb5ee6a0dfc7cb8528f27115446.jpeg)

---

<div class="post-metadata">

**Author:** ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)\
**Post date:** [February 12, 2024, 4:44pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/6 "2024-02-12T16:44:43Z")

</div>

maybe make a sprite with the height of 120 and make it to the right of the screen, so whenever it touches a tile a goomba or whatever will spawn at that tile location, i hope this makes sense XD

---

<div class="post-metadata">

**Author:** ![Jamal](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jamal](https://forum.makecode.com/u/Jamal)\
**Post date:** [February 15, 2024, 12:52am UTC](https://forum.makecode.com/t/spawning-off-screen/26804/7 "2024-02-15T00:52:36Z")

</div>

Thank you. Ive decided to use this one. Here is the unfinished game: [https://arcade.makecode.com/S35243-10831-75287-88765](https://arcade.makecode.com/S35243-10831-75287-88765)

If there is anything I need to change please say so.

---

<div class="post-metadata">

**Author:** ![Jamal](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jamal](https://forum.makecode.com/u/Jamal)\
**Post date:** [February 26, 2024, 10:27pm UTC](https://forum.makecode.com/t/spawning-off-screen/26804/8 "2024-02-26T22:27:21Z")

</div>

So i got a new problem.

Now that I’ve been working on the game a a lot I’ve recently started working on the sub areas. For some odd reason when you go in to the 4th pipe and exit it, if you are carrying a power up you go back to being small Mario. Here is the game to show you what I’m talking about: [https://arcade.makecode.com/S35243-10831-75287-88765](https://arcade.makecode.com/S35243-10831-75287-88765)
