Suptract 2 areas and spawn objects in resulting area

I have a 2D top down game. The camera follows the player. I would like to spawn enemies in random positions around the player. But for performance reasons i dont want to fill the whole map with enemies. When enemies are out of view, they will be destroyed and at the same time new enemies will spawn in the new area.

The problem is, that i dont know how to spawn enemies in an area that is the result of the subtraction between the new area and the old area, cuz i dont want to destroy the enemies from the old area which are also in the new area.

179500-paintartwork.png

In your case, I think I would address the problem by spawning enemies depending on the player’s position.

Since knowing the player position is easy (just need a reference to it), then you can simply add X and Y displacement and determine the new enemies’ position.