Đang chuẩn bị liên kết để tải về tài liệu:
Beginning XNA 2.0 Game Programming From Novice to Professional phần 2

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Sự khác biệt chính giữa các hệ thống phối hợp trình bày trong Hình 2-1 và tọa độ được sử dụng khi tạo ra một trò chơi 2-D được gọi là "màn hình tọa độ" là nguồn gốc trục không phải là ở bên trái phía dưới, nhưng ở vị trí phía trên bên trái, như mô tả trong hình 2-2. | CHAPTER 2 2-D GRAPHICS AUDIO AND INPUT BASICS 19 You probably heard about 2-D coordinate systems in school when creating simple graphics in geometry. Just to remind you Figure 2-1 represents a triangle expressed by each of its vertices in a 2-D coordinate system. Analyze the vertices coordinates to make sure you understand the concept. Vertex Coordinates X Y A 10 10 B 15 20 C 20 10 Figure 2-1. A triangle in a 2-D coordinate system The main difference between the coordinate system presented in Figure 2-1 and the coordinates used when creating a 2-D game called screen coordinates is that the axis origin is not in the bottom left but in the top left position as depicted in Figure 2-2. Compare the two figures to understand how this difference impacts the vertices definition the higher a vertex appears onscreen the lower its Y coordinate. 600 Y Y Figure 2-2. The same triangle in screen coordinates 20 CHAPTER 2 2-D GRAPHICS AUDIO AND INPUT BASICS Another detail is that the screen coordinates are directly related to the screen resolution. So if you configure your monitor to an 800 X 600 resolution that means that the X axis will have 800 pixels each pixel is an independent point onscreen and the Y axis will have 600 pixels as suggested in Figure 2-2. Drawing a Sprite Using XNA Let s now create a simple example in XNA to display a sprite in a given position on the screen. Start by creating a new project or opening the empty project you created in the previous chapter. To group the sprite image and some associated properties such as position size and velocity you ll create a simple class which will be extended later in this chapter when we explore new concepts. The following code listing presents a simple sprite class including the following properties texture Stores the sprite image using XNA s Texture2D class. This class has many properties and methods to help deal with textures you ll see some of them in Chapters 3 and 4. The texture is stored in this class as a 2-D grid