const SCREEN_SIZE_W = 256; const SCREEN_SIZE_H = 224; let can = document.getElementById("can"); let con = can.getContext("2d"); can.width = SCREEN_SIZE_W; can.height = SCREEN_SIZE_H; let frameCount = 0; let chImg = new Image(); chImg.src = "sprite.png"; //chImg.onload = draw; function update(){ } function draw(){ con.fillStyle = "#66aaff"; con.fillRect(0,0,SCREEN_SIZE_W,SCREEN_SIZE_H); con.drawImage(chImg, 0, 0, 16, 32, 100, 10, 64, 128); con.font = "24px 'Impact'"; con.fillStyle = "#fff"; con.fillText("FRAME:" + frameCount, 10, 20); } //setInterval(mainLoop, 1000/60); window.onload = function(){ mainLoop(); } function mainLoop(){ frameCount++; update(); draw(); requestAnimationFrame(mainLoop); }