+1 vote

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!

asked Apr 25 in Engine by Tomc47 (13 points)

4 Answers

+1 vote

Hello,
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 :)

answered Apr 25 by Mxt08 (73 points)
0 votes

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")
answered Apr 26 by Okan Ozdemir (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
    else:
        #player code
answered Apr 26 by Magso (2,711 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)+"!!!"
    $Timer.start()
else:
    start_my_super_cool_game()
answered Apr 26 by zen3001 (158 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 How to use this Q&A? before posting your first questions.