Android research game development leads with the scroll of the map

Source: Internet
Author: User



Smooth scrolling of people moving maps

Friends who have played RPG games should all know that RPG's game map is generally bigger today I share with you how to handle a game map that exceeds the size of your phone screen in RPG games.

animation diagram for program effectsThe principle of the map scrolling in my previous blog article describes the way people move in the screen, because the previous game map is completely filled with the entire phone screen, so there is no need to deal with the smooth scrolling of the map. This article I focus on the control of the character after the movement of the map scrolling processing. For example, for example, if the character moves to the right, if the map is affixed to the left edge of the screen, the map's coordinates will be moved first, and when the character is more than two-thirds in the screen, the map will move in the opposite direction to the character's movement to the right, in which case the character just plays the right-walking animation. The coordinates in the screen are not changed, the local figure moves in the opposite direction to the character to move to the point where the right edge of the map has been affixed to the right edge of the phone screen so the map cannot move this time the coordinates on the screen will be moved until the character is stuck to the right edge of the screen, the other three directions are identical. The previous chapter has learned the Android research game development progress bar loading does not understand can go to look down. How code is implementedOr take the character to the right for example, we need three coordinates one is m_heropos to save the character's x-coordinate in the map one is mscreenpos to save the display coordinates of the character in the screen Mmappos to save the map's display coordinates in the phone screen, Press the right mouse button after the character in the map of the coordinates plus 8 pixels (indicating the step of walking), when the person's coordinates over the screen of two-thirds need to detect whether the map is already at the boundary, using the map to draw the x-coordinate on the screen and the width of the map to determine whether equal to the width of the screen if the equation  Indicates that the map can be moved to Zofang the coordinates of the character Mscreenpos will be unchanged mmappos the map display coordinates will move the character to the left in a step position, and if the previous equation is true, the map cannot move to the left. At this time the Mscreenpos character display coordinates will move the character to the right in a step position until the right edge of the screen mmappos the map display coordinates will not change. The moving algorithm in its three directions is exactly the same. The map is rolling in a smooth Expand the study of the card Matt map buffer algorithmThis game is not called perfect in the collision with the physical layer is still a bit of a problem but the most important thing is not to use the Carmack map buffer algorithm, below I detail a carmack map buffer algorithm principle. We need a map to change the image, in order to achieve a smooth scrolling effect of the buffer graph size should be the phone screen width, so that the memory will be resident a mobile phone screen size buffer diagram. If the character is walking down to indicate that the map is moving upward, the screen will be cut out of 2 parts, the upper part of the buffer graph moved up after the buffer, the lower part is we need to update the map section, The updated lower half is combined with the top half of the map buffer to draw on the screen to complete a map update, which can greatly improve the efficiency of the game map rendering.  If you do not use this method to update the map, each time the map is moved, it will need a double for loop to re-tile a tile Once the drawing is very inefficient. When the map moves up, the Green Map section is updated with the red part of the last buffer, which is the new game map, and the other directions are exactly the same.

: If you can move the protagonist in the lower right hand corner of the game, then the map will be cut into 4 parts of the center of the screen, the red area needs to be updated with 3 parts of the map to the left of the outside part of the map beyond the lower left part of the map, the updated principle and the same as above. so it seems Carmack is a game field of genius, Mark map buffer algorithm is one of the most excellent map algorithm, if you are interested to check the information about Kmart, he is really a top game development engineer. Welcome to download the reading, or the old saying that each article will be accompanied by source code. Finally, if you still think I don't have enough detail to look at, I'm going to put the source code on it. Welcome to discuss learning rain hope to make progress together with everyone.

SOURCE Download: Heromove

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.