I haven't written a blog for some days. I have been playing a basic role for games recently, mainly because I used to make applications and I am not familiar with games. (here, I am a bit confused: on the one hand, because of the simple application, the growth of developers and the popularity of HTML5, if HTML5 mobile is fully rolled out, you can imagine it later... second:Earning more moneyThis is also the main factor for me to switch. I dare to ask what I can do without money in this age !!! I will not talk much about it. In short, the program will raise funds for me.The hardships and hardships are full of clouds. Money is king.)
Next, let's talk about a game. When we pass the level, there may be scene switching in the game, which is not familiar to the game developers. Here I will give a brief introduction to it, I will consolidate my learning knowledge and share my learning experience so that everyone can make common progress.
Implementation principle:First, we perform cliprect on the screen to obtain the corresponding rectangular module, and then fill it with the image.
Implementation of rectangle (horizontal) intersection:
/***** Rectangular scene (horizontal) */Public void dorect_h () {/** intersection of rectangles **/INT ractheight = (mscreenheight/ractcount ); // obtain the width of each rectangle. // start on the left (even numbers 0, 2, 4 ...) for (INT I = 0; I <ractcount; I + = 2) {drawfillrect (mcanvas, color. black, 0, I * ractheight, rectstep, ractheight);} // start on the right (odd 1, 3, 5 ...) for (INT I = 1; I <ractcount; I + = 2) {drawfillrect (mcanvas, color. black, mscreenwidth-rectstep, I * ractheight, rectstep, ractheight );}}
I will briefly explain the process:For the screen, we split it into 10 rectangles, And then we fill these 10 rectangles one by one. The filling is the next scenario.The same is true for rectangular (vertical) intersection.
Here, you need to understand the SAVE and restore methods of canvas.
Save: used to save the canvas status. After saving, you can call operations such as pan, zoom, rotate, miscut, and crop of the canvas.
Restore: used to restore the State saved before the canvas. This prevents operations performed on the canvas after the save operation from affecting subsequent painting.
Save and restore must be used together (Restore can be less than save, but not more). If the restore calls more than save, an error is thrown. The SAVE and restore operations on canvas are often mixed.
Implement blinds:
/***** Shutter SCENE */Public void dosquare () {/** the shutter effect uses a double for loop to modify the width of each rectangle **/For (INT I = 0; I <= (mscreenwidth/squarerange); I ++) {// calculate the number of squares contained in the width, for (Int J = 0; j <= (mscreenheight/squarerange ); j ++) {// calculate the number of squares contained in the height. drawfillrect (mcanvas, color. black, I * squarerange, J * squarerange, rectstep, rectstep );}}}
Simple Description: Based on the view width and height, cut several squares and fill them one by one.
Scroll (to the right) watermark:
/***** Scroll waterprint scenario (move right) */Public void doshadow_ringht () {/***** here, we need to calculate the width of each rectangle and the starting X coordinate ** to understand its meaning. */INT X1 = rectstep + rectx1; // The X coordinate int rectwidth1 of rectangle 1 = rectw + 12; // The width of rectangle 1 int X2 = X1 + rectwidth1 + rectx2; int rectwid2= rectw + 5; int X3 = x2 + rectwid2+ rectx3; int rectwidth3 = rectw; /** the watermark effect actually draws four rectangles and leaves some gaps between them **/drawfillrect (mcanvas, color. black, 0, 0, rectstep, mscreenheight); drawfillrect (mcanvas, color. black, X1, 0, rectwidth1, mscreenheight); drawfillrect (mcanvas, color. black, X2, 0, rectwid2, mscreenheight); // draw the second rectangle drawfillrect (mcanvas, color. black, X3, 0, rectwidth3, mscreenheight); // draw the third rectangle}
Simple Description:First, we split the screen into four rectangles. The first one will always increase and move to the right, and the other three rectangles will also move to the right, so it feels similar to the scroll ripple.The same applies to scrolling (to the left) Waterlines.
Horizontal Split field:
/***** Horizontal split image */Public void dohalf_v () {int y = mscreenheight/2; // obtain the intermediate split line int Y1 = Y-rectstep; // upper part X coordinate drawfillrect (mcanvas, color. black, 0, Y1, mscreenwidth, rectstep); // draw the top part of drawfillrect (mcanvas, color. black, 0, Y, mscreenwidth, rectstep); // draw the following part}
I will not explain this, because it is the simplest one.
Finally, let's take a look at the drawfillrect method.
/*** Draw a rectangle ** @ Param canvas * @ Param color * @ Param x * @ Param y * @ Param w * @ Param H */Public void drawfillrect (canvas, int color, int X, int y, int W, int h) {int backcolor = mpaint. getcolor (); mpaint. setcolor (color); canvas. save (); canvas. cliprect (X, Y, x + W, Y + H); int id = currentid + 1; if (ID = bitmap. length) id = 0; // drawing canvas. drawbitmap (Bitmap [ID], null, rectf, null); canvas. restore (); mpaint. setcolor (backcolor );}
This method is to fill the image with the rectangle you have cropped. The code is relatively simple and I believe everyone can understand it.
We may have discovered that our scenarios are actually produced by rectangles. This also benefits from the cliprect method provided by the API, but the API only provides the clipping of rectangles, for example, circles and arcs do not exist, so I have no way to do this, but it is good to provide rectangular tailoring. As long as you have good implementation ideas, you can build them one by one.The scenario is described here.
Below we will expand:In fact, it is not called expansion, because I am an application, so the first thing that comes to mind is what effect this stuff can achieve in the application. for example, the personalized album player. or image browsers. in fact, if you apply the effects of the game to applications, the results will be very good.
The following describes the implementation process: first, we need to customize the surfaceview control and inject the collection of retrieved image arrays into the custom control. then there is logic processing. We need to perform a switchover every five minutes, that is, the scenario switching effect. however, the best result of scenario switching is random. that's all simple.
As long as you understand the principle, it is not difficult to implement it. What is difficult is how our logic should be handled. This is also the difficulty of game development. Different from applications, application controls are all ready-made, at most, rewrite its controls to add additional auxiliary functions.So the most important thing is to be patient.
Okay. Let's take a look at the effect. (It looks pretty good. The screenshot tool is not good, so it looks like there is a card, and there is no problem with the mobile phone simulator running .)
Leave a message if you have any questions.
In addition, if it is helpful to you, remember to like one.
Here: Thanks for you!