android 遊戲開發二:遊戲的開發簡介

來源:互聯網
上載者:User

 

遊戲的組成部分:

 

 

 

1)Window management: This is responsible for creating a window and coping with

     things like closing the window or pausing/resuming the application on Android.

2)Input: This is related to the window management module, and keeps track of user

     input (e.g., touch events, keystrokes, and accelerometer readings).

3)File I/O: This allows us to get the bytes of our assets into our program from disk.

4)Graphics: This is probably the most complex module besides the actual game. It is

     responsible for loading graphics and drawing them on the screen.

 

 

 

映像顯示原理:

 

The display receives a constant stream of information from the graphics processor. It

encodes the color of each pixel in the display’s raster as specified by the program or

operating system in control of drawing to the screen. The display will refresh its state a

few dozen times per second. The exact rate is called the refresh rate. It is expressed in

Hertz. Liquid crystal displays (LCDs) usually have a refresh rate of 60 Hz per second;

cathode ray tube (CRT) monitors and plasma monitors often have higher refresh rates.

 

 

 

The graphics processor has access to a special memory area known as video memory,

 

or VRAM. Within VRAM there’s a reserved area for storing each pixel to be displayed on

 

the screen. This area is usually called the framebuffer. A complete screen image is

therefore called a frame. For each pixel in the display’s raster grid, there’s a

corresponding memory address in the framebuffer that holds the pixel’s color. When we

want to change what’s displayed on the screen, we simply change the color values of

the pixels in that memory area in VRAM.

 

 

 

雙緩衝機制

 

為瞭解決螢幕重新整理時部分顯示前一幀部分顯示後一幀

 

The first part of the solution to this problem is called double-buffering. Instead of having

a single framebuffer, the graphics processing unit (GPU) actually manages two of them,

a front buffer and a back buffer. The front buffer is available to the display to fetch the

pixel colors from, and the back buffer is available to draw our next frame while the

display happily feeds off the front buffer. When we finish drawing our current frame, we

tell the GPU to switch the two buffers with each other, which usually means just

swapping the address of the front and the back buffer. In graphics programming

literature and API documentation, you may find the terms page flip and buffer swap,

which refer to this process.

 

幀同步

 

Double-buffering alone does not solve the problem entirely, though: the swap can still

happen while the screen is in the middle of refreshing its content. That’s where vertical

 

synchronization (also known as vsync) comes into play. When we call the buffer swap

method, the GPU will block until the display signals that it has finished its current refresh.

If that happens, the GPU can safely swap the buffer addresses, and all will be well.

 

顏色

 

Physically, color is the reaction of your retina and visual cortex to electromagnetic

waves. Such a wave is characterized by its wavelength and its intensity. We can see

waves with a wavelength between roughly 400 and 700 nm. That subband of the

 

electromagnetic spectrum is also known as the visible light spectrum

 

The RGB color model is called an additive color model, due to the fact that the final

color is derived via mixing the additive primary colors red, green, and blue

 

圖片的壓縮

 

The two most popular formats are JPEG and PNG. JPEG is a  lossy format. This means

 

that some of the original information is thrown away in the process of compression. PNG

 

 is a lossless format, and will reproduce an image that’s 100 percent true to the original.

 

註:上訴幾點遊戲開發時並不需要操心,但需要瞭解。

 

 

 

 5)Audio: This module is responsible for loading and playing everything that will hit our

 

    ears.

 

    背景音樂一定不要事先載入到記憶體而是用輸入資料流,因為占記憶體太大,短小的即時音效可以。

6)Game framework: This ties all the above together and provides an easy-to-use base

     to write our games.

 

  通用遊戲架構需要實現的介面:

 

1、Set up the window and UI component and hook into callbacks so we

     can receive window and input events.

2、Start the main loop thread.

3、Keep track of the current screen and tell it to update and present itself

     in each main loop iteration (aka frame).

4、Transfer any window events (e.g., pause and resume events) from the

     UI thread to the main loop thread and pass them on to the current

    screen so it can change its state accordingly.

5、Grant access to all the modules we developed earlier: Input, FileIO,

    Graphics, and Audio.

 

 

作者 shangdahao

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.