Know another language? Translate this tutorial!


14.7K visitors
66.5K page views
1,576 translation visitors
3.7K translation page views

Randomly spawn object at random or set intervals

Favourite 71 favourites
Tutorial written by lonehangmanOriginally published on 21st, September 2012 - 3 revisions

If you're making something like a zombie survival game or just want random objects to spawn, you would find that making objects spawn randomly is a bit of a pickle.
But it's actually very simple, and can be applied to most games.

Firstly, in your layout, make a blank sprite, this is your spawner object. It can be what ever size you want. A player, and one instance of the object you are spawning (can be outside layout). Like so:

Now go to your event editor and try the following (The variable is for debug purposes, you can add it if you want):

What's happening

Every one second (this can be changed to any value, or even a random value ie. random 1-5, which will spawn at any time between 1 and 5 seconds) it will change the position of the spawner object to a random value on the map.
If the spawner object is not on screen it will spawn an object next to it and if it is on screen it will move again and try spawn something)

That's basically it!
If you are spawning zombies, you could make it that when they are created they move toward the player.

If there is anything I missed, feel free to drop a comment.

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

View deals

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!


tchem 4,058 rep

Cool......simple and objective...

Friday, October 12, 2012 at 3:28:34 AM
SciFiStudios 4,200 rep

Actually kind of pointless. No offense this would work but it's over kill if you just want them to spawn randomly. To get them to spawn randomly just make an event, every x seconds and add the action create object. Then set action parameters to...
Layer: Any layer
X: random(3000)
Y: random(3000)

Wednesday, December 12, 2012 at 9:29:32 PM
jegcelorio 3,723 rep

Great tutorial lonehangman!!

THanks SciFiStudios! Based on your comment I was able to do it using:
"System every random(2,4) seconds. System create Sprite on layer 0 at X.random(0,200), Y.random(0,200)"

Tuesday, March 26, 2013 at 2:16:46 AM
BurningWood 3,467 rep

Thank you :D

Wednesday, July 31, 2013 at 2:07:23 PM
BurningWood 3,467 rep

How do you stop the random items from spawning on top of solid objects the player cant reach?

Thursday, August 01, 2013 at 11:15:07 AM
Dannyzigg 1,522 rep

So when using either ScifiStudio's, or Lonehangman's, method you don't get much control in how random the spawn is , like if you wanted an it to spawn more often than another. Changing the seconds seems like it would very exponentially decreases the chance of it showing up. I am still rather new to this but I will work around with it and see if I can come up with something that gives you more control.

@Burningwood, again I am very new but best I can think of is to set the object to destroy when in collision with said unreachable objects.

Monday, September 23, 2013 at 12:30:46 AM
dstrawberrygirl 701 rep

I've been using sprites on a hidden layer with a series of image points spaced out over the surface of the sprite, then spawn an enemy at a random image point. For example, a rectangle with 9 image points, you spawn on the main / action / visible layer at image point random(0,8) - works well to control where enemies spawn in relation to obstacles.

Sunday, December 08, 2013 at 12:32:48 AM
mrnannings 3,508 rep

Short tut but good

Sunday, March 16, 2014 at 12:56:23 PM
luxvideo 475 rep

Very easy and simple to understand, when starting with this software, stuff like that is excellent for a starting point... from 30 mins of brain scratching, to 30 seconds of items spawning on the screen!! love it :)

Wednesday, March 19, 2014 at 1:57:25 PM
Edelplastic 687 rep

How to spawn a random bubble like in the Bust-a-Move game?

Sunday, April 20, 2014 at 1:23:43 AM
Albionix 359 rep

Hey everyone! I'm kinda stuck with the situation when I need to have the sprite to appear in several specific locations randomly with different frequency ( up to the certain point with 3 sec interval then less).
Any ideas?

Thanks a lot.

Thursday, July 03, 2014 at 6:58:56 PM
ygy 152 rep

i need help respawning enemies after they die in android studio, i was wondering if anyone could help

Tuesday, July 12, 2016 at 5:50:06 PM
giwabdul 254 rep

Is there a way to automatically increase the spawning rate as the game level progresses? could anyone help me on this.

Sunday, October 16, 2016 at 10:02:10 AM
philsthinkerbox 5,529 rep

Thank you very much!

Sunday, December 18, 2016 at 9:02:50 PM
kccarmea 216 rep

I have been looking for something like this. But I want bricks to spawn at a random spot in the air and fall down onto the ground. I just need to know how to tweak the code because I have bricks spawning above and below my floor.

Wednesday, February 08, 2017 at 8:29:13 PM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.