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...

asked Aug 16, 2017 in Engine by Robster (783 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
answered Aug 16, 2017 by YeOldeDM (1,290 points)
selected Aug 16, 2017 by Robster

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 How to use this Q&A? before posting your first questions.