Enemy spawning when player enters their screen

Hello GDevelop community! I’m new to the engine and game development in general. To learn GDevelop, I’ve decided to try to recreate the original Legend of Zelda for NES to the best of my ability. While I’ve learned quite a bit from reading other forum posts and watching tutorials, one issue I’ve run into is really stumping me.

In LOZ, it is a screen-by-screen scrolling game. When you enter a new screen, the enemies on that screen spawn. While I’ve kind of gotten this to work using various variables, I’m having trouble getting only the enemies on the “active screen” to spawn. When I enter a new screen, enemies on that screen are spawning, but so are the enemies on adjacent screens.

How can I target a specific screen for the enemies to spawn on, only when the player has entered that screen? What would be the general procedure for making this happen? Also, once the player leaves that screen, how could I delete any enemies left on the previous screen (for performance reasons), then get them to respawn only when the player enters that screen once again?

Here are the details of what I’m doing:

  • I have the screen scroll triggered by collision with a “trigger object”, and I use lerp to scroll the screen in the proper direction
  • I have invisible “Enemy Spawn” objects on each screen, which the enemies spawn from when the player enters that screen
  • I have another invisible “room” covering each screen, and I tried giving each of these objects an instance variable to identify what screen it is as a “Screen ID”

I will post screenshots of my events as needed, but I don’t see an option to do that and I’m not sure how to do it. If you would like to see screenshots, please let me know how I can share them. Again, I’m new to using the forum as an actual poster.

Thanks for all your help so far, and if you need me to elaborate on what I mean, let me know!

I’ve used the invisible room covering combined with lerping a camera focus object with success.

My camera focus object is just a hidden sprite, with the origin at the centre of the sprite. the sprite itself is centred in the room, and the camera is centred on it. When I move rooms, I lerp the camera focus object to the next location. Since the camera is centred on it, it moves as well.

I also have a sprite that fits exactly in the camera viewport. It too has it’s origin is at it’s centre. and it too is positioned on the camera focus object.

For events that move enemy spawners, enemies or other room object, I first use an event that checks for object collision with the screen cover, and as a subevent off that event I have the relevant actions each object. i.e. I filter the objects, then work on that filtered list.

I hope this makes some sense. I can provide some code screen snips if you need it.


Don’t. Just leave them be. If you use the screen cover method to determine which objects to work with, then that will be enough. Sprites sufficiently off screen won’t be drawn by GDevelop. The processing time you’d save is insignificant and unnoticeable.

Thank you very much for your reply. I’m doing the same thing, using a condition to check for the collision between the “Enemy Spawner” sprite and the “Room Cover” sprite. From there, I’ve run into the problem of targeting just the Enemy Spawner sprites in one specific room. It’s like it’s checking for the collision, and if it exists at all, it’s going ahead and spawning enemies in all the surrounding rooms where I have spawner objects as well, rather than just in the room the player just entered.

To try to put it as briefly as possible, here is what I want:
-Player enters a room: Enemies spawn from their respective invisible spawn sprites on that screen only.
-Player kills enemies and leaves room: Enemies spawn from spawn sprites in the new room the player entered.
-If player returns to previous screen: Enemies spawn again just like they did the first time.
-If player didn’t kill all enemies in a room: I don’t want even more to spawn on top of the ones that are left over from last time, otherwise the room will be overrun with enemies and cause performance issues. I guess I would also like to put a “cap” on the number of enemies that can be on a screen somehow.

I would certainly love to see the code screenshots you mentioned. I think that might help me quite a bit.

Point taken! Thank you for this information. I never knew GDevelop ignored sprites sufficiently off screen, but that is good news.