Js + canvas to move people, jscanvas

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.