+2 votes

Hey there everybody,
so some context
when i press the play button from the main menu,
it will go to the game level,
when that happens i want a 3 second countdown timer to countdown to zero before the player can actually play the level,
best example i can think of is the countdowntimer in sonic air riders on the ps2 that would count down before the player could begin the race, only i want the player to only be able to play the game after the 3 second countdown,
what i have:
is a control node, then child to that is the label node, then child to that is a timer node,
when the timer reaches zero i also want it to disappear from the screen so a temporary countdown timer as well.

i hope that all made sense,
thank you!

in Engine by (14 points)

4 Answers

+1 vote

for the timer countdown I leave you with a link that I think can help you:
Timer CountDown

For the part where the player can't play until the countdown is over, I recommend pausing the game and putting the timer on the pause process mode tab, and that when that time has passed, start the game and you change the visibility of the timer (this is done by putting in the code the name of the node that represents the timer and adding to it .visibility = hidden or invisible) and it would be done.
I hope these tips help you.
Mxt08 :)

by (353 points)
–1 vote

You just need to write before load scene

func _ready():
    yield(get_tree().create_timer(2), "time_out")
    Change_scene_to("dada/your level.tscn")
by (193 points)
0 votes

There are two main ways of doing this. There are ways of doing it using the timer node but I've personally found it to be unnecessarily awkward.

Mxt80's answer but in code

func _ready():
    get_tree().paused = true
    yield(get_tree().create_timer(3), "timeout")
    get_tree().paused = false

Or make the player ignore any movement until a timer runs out.

var timer = 3.0

func _process(delta):
    if timer > 0:
        timer -= delta
        #player code
by (3,247 points)
0 votes

use the Timer node.
add it as a child node to your level.
set it's wait time property to 1 second.
go to the signals tab of the node and connect the timeout() signal to what ever script you want to use for it, just make sure you can access the timer node from the script.
in the script create an integer variable with the value of 3.
in the signaled function, reduce the value of your variable by one, check wether it's reached 0 and if not, restart the timer, else you can start the game.

the script then should look something like this:

func timeout_signal():
countdown -= 1
if not countdown == 0:
    $Label.text = str(countdown)+"!!!"
by (304 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.