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

Get help using Construct 2

Post » Fri Apr 11, 2014 9:44 am

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 :mrgreen:
B
16
S
4
Posts: 138
Reputation: 1,454

Post » Fri Apr 11, 2014 10:58 am

I think this is what you are after.
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Fri Apr 11, 2014 11:12 am

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?.
B
16
S
4
Posts: 138
Reputation: 1,454

Post » Fri Apr 11, 2014 11:26 am

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.

Image
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Fri Apr 11, 2014 11:41 am

Ah thanks a lot. Seems so simple now. I didn't think about putting a variable for it. thanks again
B
16
S
4
Posts: 138
Reputation: 1,454

Post » Fri Apr 11, 2014 11:53 am

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.
B
22
S
6
G
10
Posts: 1,036
Reputation: 7,518

Post » Fri Apr 11, 2014 12:33 pm

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.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Fri Apr 11, 2014 2:57 pm

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.
B
16
S
4
Posts: 138
Reputation: 1,454


Return to How do I....?

Who is online

Users browsing this forum: evillair and 6 guests