logoalt Hacker News

otikiktoday at 9:19 AM1 replyview on HN

So the simple case is using some sort of state variable:

switch(game_state):

  case(paused):
     <the paused logic goes here>

  case(gameplay)
     <updating entities and regular gameplay goes here>

You still have to be careful about how you implement "gameplay", though. For example if at any point you read the 'system clock' to do time-based stuff like animations or physics, then when you unpause you suddenly will have a couple minutes of advance in a place where you expect fractions of a second.

Replies

diathtoday at 9:43 AM

This is why delta time accumulator is preferred over using clocks, something like this would be best:

    float accum = 0;
    while (running) {
        poll_input();
        poll_network();

        accum += delta_time;

        while (accum >= tick_time) {
            accum -= tick_time;

            update_ui(tick_time);
            update_anims(tick_time);

            if (!paused) {
                update_entities(tick_time);
            }
        }

        render();
    }
show 3 replies