Android game development Practice on the smooth rolling processing of the moving map _android

Source: Internet
Author: User

As shown in the picture for the program effect animation diagram

The principle of map scrolling

In my previous blog article introduced the characters in the screen movement way, because the game map before spell is completely filled with the entire mobile phone screen, so no need to deal with the smooth scrolling map. This article I will focus on the control of the movement of people after the map scrolling processing. For example, as shown in the figure above, the character moves to the right, if the map is affixed to the left edge of the screen will first move the characters in the map coordinates, when the characters in the screen more than two-thirds after the map to the character to walk in the opposite direction to the player a character is still moving the illusion, in fact, this time the characters just play the right to walk animation The coordinates in the screen are unchanged, the local map to the character walking in the opposite direction to move to the point that the right side of the map has been affixed to the right side of the phone screen, so the map can not move at this time to move the characters on the screen coordinates until the character is affixed to the right side of the screen, the other three principles are

How code is implemented

Or the figure to the right to move for example, we need three coordinates one is m_heropos to save the figure in the map of the X coordinate one is mscreenpos to save the characters in the screen display coordinates mmappos to save the map on the phone screen display coordinates, After pressing the right key of the keyboard, the character's coordinates in the map plus 8 pixels (indicating the step length of the walk) when the figure's coordinates exceed the screen two-thirds, you need to check whether the map is already at the boundary, use the map to draw the X coordinates in the screen plus the width of the map to determine whether the width of the screen is equal to that of the screens if the equation does not It means that the map can move to the Zofang. This time after the characters Mscreenpos figure display coordinates will not change Mmappos map display coordinates will move the character a step to the left position, if the previous equation is established then the map can not move to the left At this time Mscreenpos figure display coordinates will move the character one step position to the right side of the screen until the right border Mmappos map display coordinates will not change. The moving algorithm in the three directions is exactly the same.

As shown in the picture map in the smooth scrolling

The development of learning card Matt map buffering algorithm

This game demo can not be called perfect in the collision with the physical layer or there is a problem, but the most important thing is not using the Carmack map buffer algorithm, the following I detail a carmack map buffer algorithm principle. We need a map to change the image, in order to achieve smooth scrolling effect of the buffer map should be the size of the phone screen is wide, so that the memory will be resident on a mobile phone screen size buffer map. If the character walks below it means the map is moving up, then the screen will be cut out 2 parts, the upper part is the buffer content that moves up after the buffer chart, the lower part is we need to update the part of the map, the lower part of the update is combined with the top half of the map buffer to draw in the screen, then completes a Map update, which can greatly enhance the efficiency of the game mapping. If you do not use this method to update the map, each time the map is moved, it requires a double for loop to tile a tile the efficiency will be very low.

As shown in the map after moving up to update the green map part of the last buffer with the red part of the new game map, the other direction is exactly the same.

As shown in the figure: if the game can be the right way to move the protagonist then the screen in the lower right corner of the center map will be cut into 4 parts the red area in the image below needs to be updated with 3 parts of the map to the left beyond the part of the map below the left part of the map beyond the bottom, the principle of updating is the same as above.

So it seems that Carmack is a genius in the field of game, Mark map buffer algorithm is worthy of one of the most excellent map algorithms, if you are interested to check the information on Kmart, he is indeed a top game development engineer.

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.