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)