Last active
September 11, 2015 03:18
-
-
Save allysonsouza/442ceea4497cb4124ecd to your computer and use it in GitHub Desktop.
JavaScript Simple Didatic Game Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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