0 votes

Hi all,

Starting a new game. This game will want time to tick on by.
Y1 W52 D28

I want the game to have two speed settings and the ability to pause as I enter menus etc.

Should I use a timer for this?
The thing is I want to start at 0 and count UP I'm guessing.

Does anyone have any suggestions on the best way to tackle this?

Thanks so much...

in Engine by (835 points)

1 Answer

+1 vote
Best answer

You can easily increment a timer variable in a _process(delta) function. Adding delta to a value will cause that value to increase by 1 per second. You can multiply this by a value to get different "speeds" and prevent time from increasing with an if check to pause time.

var time = 0
var time_mult = 1.0
var paused = false

func _ready():
  set_process(true)

func _process(delta):
  if not paused:
    time += delta * time_mult
by (1,328 points)
selected by

So simple and elegant. Thanks a tonne... Much appreciated.

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.