How do I make an effective way to spawn enemies off screen?

0 favourites
  • 7 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Before I tackle this I wanted to see others think before I attempt it myself first.

    What i'm trying to achieve is an infinite game, I want the player to endlessry run around killing enemies and they'll re-spawn outside the player's field of view. But how i've concepted it goes like this:

    At the beginning of the layout i'm going to spawn a bunch of enemies in the room.

    I figured that i'd just check to see how many instances of the object are in the layout and if it goes under a certain amount of instances i'd spawn more but the problem is, if I spawn one and set the location as random.

    Then there's a chance it will spawn on the player or within the players field of views. I don't want this.

    So I concept that i'd make a bunch of spawners and scatter them all around the map so the game just chooses one of them as a spawn location for the enemy. But I still don't know how to remove the spawners that are in the players field of view from the choose() function. I'm still pretty new.

    I thought up this way, but it seems a bit ineffective and the amount of object spawners on the map might cause performance issues for lower spec computers since I want to make the map quite large. If I had to compare what I'm trying to achieve to a game. Check out someone fighting in Godlands in Realm of the Mad God. Although it's a small area in the map enemies will constantly re-spawn as long as players aren't around.

    If there's any easier alternatives i'd love to hear them. Thanks for your time.


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'd say you should stick with choose().

    What you need to do, is create an event (e.g. System -> Create new object) to spawn your enemy and set the X and Y coordinates to choose(...).

    Also create two dictionaries, one for the X coordinates and one for the Y coordinates. Now, at the start of the layout,add values to the dictionaries. As the key, go numeric, starting from 1 and go up to the number of spawn points you want.

    The first value that you assign to the X dictionary will be the equivalent Y coordinate in the Y dictionary.

    Now, you fill the choose brackets. For the X coordinate, it will be Create object: X: DictionaryX.Get(str(choose(1,DictionaryX.Keycount))) The same for the Y coordinates, just with the Y dictionary of course.

    By doing this, you have random spawn places while assuring that no X and Y coordinates are being chosen that you don't want together.

    If you need any more help or a .capx, give me shout.

  • If it doesn't bother you if the enemies are placed in random outside your viewport you have only to look which area you cannot see. The area you can see is called viewport. The area you cannot see is between the borders of the layout and the viewport. So you need the coordinates of the viewport and the size of the Layout. Luckiey Constrcut2 provides this. There are ViewportLeft, ViewportTop, ViewportRight, ViewportBottom, LayoutHeight, LayoutWidth.

    Now you have to calculate the area which you cannot see. You need a x and y position:

    0<x< viewportLeft or viewportRight<x<LayoutWidth

    0<y<vieportTop or viewportBottom<x<LayoutHeight.

    Now you have the coordinates to spawn an enemy which is not created in the viewport. I made a litte example maybe it's easier to understand. ... sp=sharing

  • randomly

    I sort of understand. I'll need to run it through Construct first to get a feel for it. The only drawback is I was probably going to set the X and Y positions as follows:

    X ---> spawner.x(specific instance) + random(-250,250)

    Y ---> spawner.y(specific instance) + random(-250,250)

    This was enemies don't spawn EXACTLY on the spawnpoints, just around that general area. I mean I would just set the enemy so that it waits 0.1 seconds after it has been creation to add (-250, 250) to both the X and Y values it already has after being sent to one of the spawners but.


    It get what you mean, to an extent, since i've never tried it before it's a bit hazey for me. If I can get this to work i'll probably go with this one since FOR NOW i'm not bothered where enemies spawn but later down the line I might add other biomes in so specific enemies will appear there. I downloaded the files you sent me on Google Drive. But when I launch them in Construct 2 it says it can't locate the Layouts? It refuses to launch it at all. Even says to me that the animations are missing for objects but I can see them in the folder... Any idea as to why it's doing this?

  • The capx works for me. I put it up again maybe it's corrupt. Please try to download it again. ... sp=sharing

    If it doesn't work here this is how it looks like. Sprite has a ScrollTo and a 8Direction behavior:

  • Asmodean

    It's still giving me the same errors. What is the conditions for events: 3, 5 and 6?


  • It shouldn't give you any error. I tried the download and it works fine for me. However I made a zip-file. That should not be necessary , because the capx is itself a zip-archive, so it's now a zip in a zip archive. ... sp=sharing

    Event 3 is 'compare two values' in System/General

    Event 5 and 6 are 'is between values' in System/General

    Event 6 is a subevent to event 5. Both events are or-blocks. Make two conditions, highlight the whole block and make a right click on it an choose 'make or-block'

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)