html5 动画精灵
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div style="position:absolute;top:50px;left:50px;"></div> <canvas id="canvas" width="80" height="98"></canvas> <script type="text/javascript"> window.addEventListener("load", eventWindowLoaded,false); function eventWindowLoaded(){ canvasApp(); } function canvasApp(){ var theCanvas=document.getElementById("canvas"); var context=theCanvas.getContext('2d'); counter=0; var tileSheet = new Image(); tileSheet.addEventListener('load', eventShipLoaded , false); tileSheet.src = "1.png"; function eventShipLoaded() { startUp(); } function drawScreen() { context.fillStyle = "white"; context.fillRect(0,0,500,500); context.drawImage(tileSheet,80*counter,288,80,96,0,0,80,96); counter++; if (counter>1) { counter=0; } } function startUp(){ setInterval(drawScreen, 200); } } </script> </body> </html>
posted on 2013-07-15 14:49 Ijavascript 阅读(489) 评论(0) 编辑 收藏 举报