The realization of 2d game oblique view Map

Source: Internet
Author: User
Tags current time time interval

Description

A, this procedure is a oblique view of the map of the rolling screen demo. This program does not take into account the screen rendering efficiency and memory space saving problems when implemented. So the map-rendering function does not exclude parts of the tile that are not visible. The implementation of this program fully adopted the Win32 assembly language, so the use of GDI interface can also get better frame speed.

Second, this procedure reflects the 2d game map control ideas. That is, the core problem is a number of coordinate transformation problems, to solve the coordinate transformation on it.

1, save the map of one-dimensional data index. You need to turn this one-dimensional array index into map coordinates, i.e. (column number, line number). After this step, the drawing program can traverse the entire one-dimensional array, just like traversing

A two-dimensional array of map blocks as well. That is, the array index determines that it is the coordinates on the map.

2, map coordinates----the plot number, line number. Map coordinates are transformed into screen mapping coordinates. Because the map coordinates are (column number, line number), therefore must solve the map block in the upper left corner pixel coordinates, namely the mapping coordinates.

3, to carry out the visual transformation. That is, when the map is very large, the viewport held on the map for translation can achieve the scrolling map, see the different parts. Therefore, once the upper left corner of the viewport is determined by the absolute coordinates on the map, the relative coordinates of a map block within the viewport------The final window client area mapping coordinates can be obtained.

4, after a few steps of transformation, a map block can really be drawn to the inside of the window.

Third, frame speed control:

A, use variable timeold to record the last time the frame rate was calculated.

B, variable timenew record the current time.

c, using variable Framecount record the number of frames played from timeold to timenew intervals.

D, after each acquisition of the current time timenew, please since

How much time does the last calculated frame speed end to now (ms): Timenew-timeold

When this interval is greater than 1 seconds, a frame-rate calculation is performed and the Timeold = Timenew,framecount is also zeroed, ready to replay the frame playback from now on for the next second.

E, with Timecur for time tracking, so that frame speed control.

Timecur records the last time a frame ended. Timenew-timecur indicates how much time has elapsed since the last time a frame was played.

So if a frame is played every time Timenew-timecur > 10 is made, then Timecur = Timenew for the next frame of play time interval control. This allows us to control the maximum playback of one frame per 10ms, which controls the frame speed.

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.