Skip to content

Instantly share code, notes, and snippets.

@mlms13
Created February 21, 2019 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlms13/92191c2085803733f6be72a24e0983c6 to your computer and use it in GitHub Desktop.
Save mlms13/92191c2085803733f6be72a24e0983c6 to your computer and use it in GitHub Desktop.
Like TEA, but for a game loop?

The Elm Architecture, specialized for games.

Key points:

  • Instead of reacting to events, application state is updated on regular intervals
    • The engine collects all input events (keys up/down, mouse movement, button clicks, possibly joysticks, game pads)
    • User of this library specifies how to translate diffs in input events to game actions
  • Instead of a single "update" function, there are several specialized functions
    • physics update
      • given a current state (which should include things like position and velocity) and a time delta, provide a new state
      • run on regular intervals, as often as possible
    • input update
      • given changes in user input, update the state
  • instead of drawing virtual dom in response to events...
    • draw on a canvas
    • at intervals that are synced with animation frames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment