Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Last active September 11, 2015 03:18
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 allysonsouza/442ceea4497cb4124ecd to your computer and use it in GitHub Desktop.
Save allysonsouza/442ceea4497cb4124ecd to your computer and use it in GitHub Desktop.
JavaScript Simple Didatic Game Loop
var canvas;
var contexto;
var naveX = 400;
var naveY = 400;
function init() {
canvas = document.getElementById("game");
contexto = canvas.getContext('2d');
nave = document.getElementById("nave");
setInterval(loop, 1000/60 );
}
function loop() {
update();
draw();
}
function update() {
naveX++;
naveY--;
}
function draw() {
contexto.clearRect(0, 0, canvas.width, canvas.height);
contexto.drawImage( nave, naveX, naveY);
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment