Miscellaneous: read a lotProgramYuandu has the habit of writing a blog. It seems that I have to practice it too. No matter what the writing is, write it if you have learned something.
Content Description: I have been learning how to create game maps over the past few days. Today I will briefly summarize the use of the canvas cliprect () interface.
1) Select the area where you want to draw (refresh) on the canvas, with (x, y) as the starting coordinate, width W, and height H.
2) Select the image to be drawn, not necessarily the width and height (W, h). You need to cut the large image (in this example, the green area is drawn)
3) draw an image on the canvas to make the green area overlap with the white block.
4) Last
CodeExplanation:
Copy codeThe Code is as follows: canvas. Save ();
Canvas. cliprect (x1, Y1, X1 + W, Y1 + H );
Canvas. drawbitmap (bitmap, X2, Y2, paint );
Canvas. Restore ();
1. Save () first saves the canvas data (such as matrix), and then restore () after the painting is complete. Then, forget is performed on the canvas coordinates in the middle;
2. cliprect () captures an area in the canvas;
3. When drawbitmap () is used to draw an image on (X2, Y2), the green part is drawn on (x1, Y1), but not on the clip area;
4. At last, restore () needs to restore the canvas to the original data (remember to pair save () with restore ).
5. Little code, a lot of nonsense