HTML5 Canvas animation effect graphic code demonstration

黄舟
Release: 2017-03-22 14:51:56
Original
3279 people have browsed it

HTML5 Canvas animation effect demonstration

Main idea:

First, prepare a picture with consecutive frames, and then use the draw method of HTML5 Canvas to draw different frames at different time

intervals, so that it looks like the animation is playing.

Key technical points:

The JavaScript function setTimeout() has two parameters. The first one is that the parameter can Pass a JavaScript method,

The other parameter represents the interval, in milliseconds. Code example:

setTimeout(update, 1000/30);

Canvas API-drawImage() method, all 9 need to be specified Parameters:

ctx.drawImage(myImage, offw, offh, width,height, x2, y2, width, height);

where offw, offh refer to the starting coordinate point of the source image, width, height represent the width and height of the source image, x2, y2 represent the starting point of the source image on the target Canvas Coordinate points.

The effect achieved by a 22-frame wild goose flying picture:

## Source image:

Program code:

     Canvas Mouse Event Demo   

HTML Canvas Animations Demo - By Gloomy Fish

Play Animations

Copy after login

I found there was a problem uploading transparent PNG format, so I uploaded

opaque images. You can replace it with other pictures. After replacement,

please modify the maximum frame number from 22 to your actual frame number to run.


The above is the content of the HTML5 Canvas animation effect graphic code demonstration. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!

Related articles:

How to use HTML5 Canvas to create 3D animation effects

CSS3 animation to achieve 5 preload animation effects

Summary analysis of css3 animation effects

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!