Construct 2 r51 introduces a really handy new action: the System "wait" action. Here's how it works.
The Wait action waits a number of seconds before running the next action. It remembers all the picked objects so it works exactly like a normal event, just a bit later in time. During the wait, the rest of the event sheet continues to run as normal.
For example, consider:
+ On spacebar pressed
-> Player: spawn a bullet
-> Audio: play 'bang' sound
If you hit spacebar, your bullets emerge with a bang immediately. If you add a Wait action, though:
+ On spacebar pressed
-> System: wait 1 second
-> Player: spawn a bullet
-> Audio: play 'bang' sound
If you hit spacebar, there's a one second delay, then the bullet emerges with a bang. If you tap spacebar twice quickly, it queues up twice, so two bullets are shot, each one second after you hit spacebar.
You can also use the wait action multiple times in an event. For example:
+ On start of layout
-> Text: set text to "Hello there!" & newline
-> System: wait 1 second
-> Text: append text "How are you?" & newline
-> System: wait 1 second
-> Text: append text "Nice to meet you!"
This event adds each message to the text object at one second intervals. Don't forget the rest of your events are running as normal while the waits are waiting. Any events can set up as many waits as they want at any time, and it all runs as scheduled.
Here's another example:
+ Every 1 second
-> Sprite: set invisible
-> System: wait 0.3 seconds
-> Sprite: set visible
The sprite flashes.
One more example:
+ Every 2 seconds
-> Enemy: spawn 'bullet'
-> System: wait 0.2 seconds
-> Enemy: spawn 'bullet'
-> System: wait 0.2 seconds
-> Enemy: spawn 'bullet'
Every 2 seconds, the enemy fires a salvo of three bullets, each 0.2 seconds apart.
If you're feeling super pro, you can schedule events in loops too:
+ On start of layout
+ Repeat 10 times
-> System: wait loopindex seconds
-> Text: append text "Time = " & time & newline
This one event will cause a new line to be added to the text object every one second for ten seconds. This is because the "Repeat 10 times" condition runs the actions ten times, and each run schedules a wait of a different length of time followed by adding a line of text. This spreads all the "append text" actions out over time.
For advanced users
The Wait action saves the state of the entire SOL and cancels the current event. When the wait time has expired, the entire SOL as it was is restored (minus any objects that got destroyed), and the event is resumed from the action following the wait action. It continues to run any subevents as well. At any point if another wait action is encountered, the same save-SOL-and-wait process happens, so you can make different parts of an event run at different times.
One more trick: "Wait 0 seconds" postpones the following actions until the end of the event sheet.
Conclusion
This is really powerful feature. If you ever used Construct Classic, you should find it a much more elegant solution than the Function object's "call after delay". Scheduling things over time by events has always been a bit of a headache, so hopefully this makes it nice and simple!
Total of
2 edits. Last edit by
Ashley on
22 August 2011 7:31 PM