Skip to content

Instantly share code, notes, and snippets.

@CodeDraken
Last active December 5, 2019 10:01
Show Gist options
  • Save CodeDraken/6698d4aa700612039782a4b426f69e41 to your computer and use it in GitHub Desktop.
Save CodeDraken/6698d4aa700612039782a4b426f69e41 to your computer and use it in GitHub Desktop.
// global variables that will be loaded/initialized later
let canvas, ctx, gravity, ball, friction
// runs once at the beginning
// loads any data and kickstarts the loop
function init () {
// load and initialize data here
// ...
// begin update loop
// ...
}
// draws stuff to the screen
// allows us to separate calculations and drawing
function draw () {
// clear the canvas
// ...
// draw things
// ...
}
// the main piece of the loop
// runs everything
function update () {
// queue the next update
// ...
// logic goes here
// ...
// draw after logic/calculations
draw()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment