How do I control the time of an object's creation

0 favourites
  • 8 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Ok, Imagine a dodge-ball game where a ball is created every 5 seconds and hurled towards the player , and the player's goal is to avoid it.

    Now when the player is hit, it toggles a variable which stops the balls from being created and hurled, towards the player.

    Then a 'are you ready?' button pops up, which if clicked would toggle the variable again, and the balls being created every 5 seconds, will resume.

    The problem is, Imagine i clicked the 'are you ready' button 1 second after it pops up, then the ball appears 4 seconds later. I click the button 3 seconds after it pops up, the ball is created after 2 seconds. You see where i'm headed.

    So if i waited for a long time to click, past 5 seconds. Say i clicked it after 8 seconds,then a ball immediately flies into the screen. This catches the player off guard. How do i prevent this.

    Same issue while restarting the layout. If i restart it with just 2 seconds left for a ball to be created, on the restarted layout a ball appears after 2 seconds only. If there was only 0.00009 seconds remaining for a ball to be created, then on the restarted layout a ball appears immediately. Unlike where it takes 5 seconds for a ball to come if i started the layout for the first time.

    Anyone have a solution?

    Sorry for the essay lol

  • I think this is what you are after.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Argh i don't have the latest version of C2 , so i couldn't open it. My internet is the bane of the universe and i have others at home using it so i can't really upgrade now. Anyway to open it otherwise?.

  • No other way as far as I know. Quick explanation see if that helps.

    Have global variables "Shoot=0" & "playing=0"

    Every 1 second add 1 to shoot but only if playing=0.

    When shoot = 5 create your ball and set shoot back to 0.

    When the ball collides with the player set "playing=1" and "shoot=0"

    create your button or make it visible or whatever you are doing.

    When your button is pressed set "playing=0"

    and because a picture is worth a thousand words here's a screen of my events that I threw together.

  • Ah thanks a lot. Seems so simple now. I didn't think about putting a variable for it. thanks again

  • You could also use the timer behavior for this I guess.

    What I usually do is create a variable for this kind of purpose. When the variable is 0, the time has elapsed and you spawn a ball or do whatever and set the variable again to the desired amount of time (I use ms, so it would be 5000).

    Then obviously have an (every tick) event which subtracts 1000*dt from the variable. This will take exactly one second to subtract 1000. Delta time is important!

    If you just use every 1.0 second, you will always have inaccuracies, since this runs on the general game timer. So in the example above in all likelihood the variable "playing" could be set to 0 again when the time is somewhere between a full second , making it only take 4.x seconds to spawn a ball.

  • Go with Pixel's method for the timer in your full game.

    Like he said "every x seconds" will be inaccurate but using "every x second" was a lot easier and quicker for throwing together an example.

  • Thanks both, I ended up using PixeRebirth's method , seeing as he mentioned it was more accurate. I had to add more events though and a sub event to only trigger the ball spawn once. Lol i didn't at first and my screen was filled with them.

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