Timer to Spawn Object Every X Seconds

0 favourites
  • 10 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • Have tried to figure this out using the timers here:


    but have not had any success. In short I am wanting to spawn an object on a layout every say 30 seconds. However at the start of a layout I want to start over and thus the construct statement "every x seconds" wont work as that is a revolving clock.

    So I created a global variable "timer=0"

    Add 1 to timer every 1 seconds

    Set timer to 0 at the start of layout

    Now my only question is how to get it to spawn the object every thirty seconds using my timer variable above?

    I tried when timer/30 is equal to integers 1-50 but int doesnt work that way, I was basically trying to get it to only spawn when it was a multiple of 30. Any ideas much appreciated.

  • That tutorial is out of date. Use the new Timer behaviour.


  • To get objects to spawn every 30 seconds you could try:

    Every 1 second - add 1 to (Variable)"Timer"

    If (Variable)Timer is greater than 30 - set value to zero

    Then on (system) on end of layout - (system) reset global variables

  • EyezWidee you can also add 1 every second by doing:

    Every Tick: Add 1 * dt to Variable "Timer"

    The reason for that is to make it work even if the game gets laggy (dt always adds up to 1 every second). It's used in most of the built-in plugins to keep them smooth.

    Ashley wrote a good tutorial on it too here: https://www.scirra.com/tutorials/67/delta-time-and-framerate-independence

  • Okay thats actually pretty interesting I didnt know that, I try to avoid using every tick with variables feels like it hinders the performance especially when it involves webstorage. But I'll deff give that try also.

  • Both are excellent answers, thank you I greatly appreciate it.

    One questions for clarification does the new timer behavior also work on dt so in the event the game was lagging it would behave correctly?

  • kenn

    Var = Difficultly

    Every X Second= add 1 to difficulty

    System Var Difficulty is greater than 5

    "Add another condition"

    System Var Difficulty is less than than 30

    "Sub event"

    Every 1 second

    Action create object (enemy) (How and where you want)


    Here is a link to how I have mine set up (works for me)

  • Yes, Timer uses dt.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • as another alternative

    var nextTime

    var timedelay

    On start of Layout

    nextTime = time + timedelay

    Event: nextTime <= time

    do your creation

    nextTime = time + timedelay

  • Thanks everyone for the input. Glad that the timer uses dt, ultimately I went with the timer plugin and found that I could add quite a few variations and variables leveraging what was already built into it. Thanks again.

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