Js + canvas to move people, jscanvas
I read an online picture of the runner Maria walking around. I felt that the person was walking too fast. I wrote the code to modify it:
Js Code:
// Define the Array image set var marios = new Array ("image/QQ20141119164825.png", "image/QQ20141119164845.png", "Image/QQ20141119164908.png"); var mario = new image (); var canvas; var ctx; var I =-1; var num = 0; function init () {// alert ("----------") setInterval ("draw ()", 200);} function draw () {I ++; // alert (I) mario. src = marios [I]; // alert (mario) canvas = document. getElementById ("mycanvas"); ctx = canvas. getContext ("2d"); ctx. clearRect (0, 0,400,100) ctx. drawImage (mario, num, 0); num + = 10; if (num = 400) {num = 0;} if (I = 2) {I =-1 ;}}
Html code:
<Body onload = "init ()"> <canvas id = "mycanvas" width = "400" height = "100" style = "border: 1px solid #888888; "> </canvas> </body>
Image: