Some summary of the Android canvas rotate rotation (some note points of rotation)

Source: Internet
Author: User

When customizing the control and using the Surfaceview to lock the canvas with Serfaceholder to draw the game, the tank picture needs to be drawn according to the direction of the tank, so the canvas's rotate (float Degrees) method, tried many times to cause the picture on the screen to be a mess, not according to the imagination. After a lot of attempts finally mastered a rule:

The canvas rotates following when it is drawn:

1, Canvas.draw (bitmap, left, top, paint) in left, top is always according to the coordinates of the canvas, no matter how to rotate.

2, when we call rotate (degrees), the first is to display the previously drawn image on the screen ( when the screen appears to be consistent with the canvas layout ), and then rotate the screen to draw the following image in the coordinates of the canvas.

3, when we call rotate (degress) again, will rotate once the image that is drawn after the display in the window, ( note, because the screen rotated once, so the screen shows the first rotation of the picture relative to the screen is rotated ).

4, loop in turn, each time you rotate the canvas, the system will draw the image to the screen, and then continue to draw later.

  

Node: In order to avoid the clutter of the screen, as with the OpenGL drawing, when we draw our own rotated image, the canvas is restored, that is, if you rotate 15 degrees, and you finish drawing the picture you want to draw, rotate again-15 degrees.

Some summary of the Android canvas rotate rotation (some note points of rotation)

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.