A Choice or an Input can have a time limit. While it runs, a thin bar along the top of the game screen shrinks from full width to nothing. When it’s gone, the engine runs the function you gave and removes the bar. That bar is a <timer-display>.

The Palacio de Bellas Artes at night, its lamps lit, with two choices, Left and Right; a thin light bar along the top edge of the screen is a little more than half full
A timed choice, about half way through

Tag <timer-display>
Where it lives Created by the Choice and Input actions at the start of <game-screen>
Built on Component
Source src/components/timer-display/

How to show one

Add a Timer to a Choice or an Input statement, with the time in milliseconds and the function to run when it’s up:

{
  'Choice': {
    'Dialog': 'y Quick, pick one!',
    'Timer': {
      time: 5000,
      callback: function() {
        document.querySelector('choice-container [data-choice="Left"]').click();
      }
    },
    'Left': {
      'Text': 'Left',
      'Do': 'y Too slow, so left it is.'
    },
    'Right': {
      'Text': 'Right',
      'Do': 'y Right!'
    }
  }
}

The timer decides nothing by itself: when time is up it runs callback (with this set to the engine) and disappears, and the choice or question stays on screen unless your function does something about it. This one clicks the Left option for the player. If the player answers first, the bar is removed and callback never runs.

Never write <timer-display> in index.html.

Markup

<timer-display data-component="timer-display" class="animated" time="5000" step="50">
  <div style="width: 54%;"></div>
</timer-display>

The inner <div> is the bar; its width goes from 100% to 0% in a hundred steps.

Properties and attributes

Name Type Default What it does
time number 0 How long the timer lasts, in milliseconds.
callback function does nothing What runs when time is up.
step number time / 100 How often the bar shrinks. The component sets it.

Events

None of its own.

Style it

The element is a strip 0.5rem tall along the top of the game screen, above everything else (z-index: 100). The bar is white at 20% opacity, so it can be hard to see on a light scene. In your game’s style/main.css:

timer-display {
  height: 0.75rem;
}

timer-display div {
  height: 100%;
  background: #ffd23f;
}

Replace or extend it

Most games only restyle it. A subclass can override render(), which draws the bar from the value state (the percentage left); the countdown itself runs in didMount(). Register it with monogatari.registerComponent() in js/main.js above $_ready(…).