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. Look like this It sounds like an animation is playing. Key technical points: The JavaScript function setTimeout() has two parameters. The first parameter can be passed to a JavaScript method. The other parameter represents the interval in milliseconds. number. Code example: setTimeout( update, 1000/30); Canvas’ API-drawImage() method requires specifying all 9 parameters: ctx.drawImage(myImage, offw, offh, width,height , x2, y2, width, height); where offw, offh refers to the starting coordinate point of the source image, width, height represents the width and height of the source image, x2, y2 represents represents the position of the source image in the target The starting coordinate point on the Canvas. The effect achieved by a 22-frame wild goose flight picture:
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 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