How to use canvas in JavaScript to rotate a picture by itself

Source: Internet
Author: User

Recently wrote a game, want to let a character with the mouse in situ rotation

Found on the Internet, most of it is written in CSS, but for the sake of long-term interests to choose to use the JavaScript code in the canvas to solve the drawing problem

Among the two important methods:

Context.translate (x, y)

Used to reset the origin of the canvas

Parameter is the set origin coordinate

Context.rotate (Angle *math.pi/180)

Let the picture rotate,

The parameter refers to the radian of the rotation

If you want to fill in the angle, multiply the math.pi/180 as above.

Core ideas:

Reprinted from: http://jingyan.baidu.com/article/ab0b56309719bac15afa7de9.html

How to use canvas in JavaScript to rotate a picture by itself

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.