Đang chuẩn bị liên kết để tải về tài liệu:
Building XNA 2.0 Games- P5
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Building XNA 2.0 Games- P5: I would like to acknowledge John Sedlak, who saved this book from certain doom, as well as all of the great guys in the XNA community and Microsoft XNA team, who helped me with all of my stupid programming questions. (That is actually the term used—“stupid programming question”—and it is a question that one should not have to ask if one has been approached to write a book about the subject.) | CHAPTER 5 THE CHARACTER EDITOR 107 So far we re iterating through all images for each texture getting the source and destination rectangles so that we can draw them in a neat row on the bottom of the screen. Of course the special case with weapons is coming right up if l 3 sRect.X i 4 80 sRect.Y i 4 64 sRect.Width 80 if i 15 dRect.X i 30 dRect.Width 30 With the correct source and destination rectangles we draw the image. But since we have the destination rectangle we might as well check if the mouse location is within the rectangle and clicking spriteBatch.Draw texture dRect sRect Color.White if dRect.Contains mouseState.X mouseState.Y if mouseClick charDef.Frames selFrame .Parts selPart .Index i 64 l spriteBatch.End Assuming we add a call to DrawPalette and DrawCursor at the end of Game1.Draw somewhere we ll be treated to the result shown in Figure 5-6. Also be sure to set mouseClick to false at the end of the Draw method. 108 CHAPTER 5 THE CHARACTER EDITOR Figure 5-6. Icon palette The Parts List We ll use the icon palette to specify which image index each part uses. The parts list will allow us to manipulate our composited character in a way similar to a layer-heavy image-editing approach. We ll be able to select a part to manipulate move parts up and down the list like Send to Bottom and Bring to Top in layer ordering and delete parts. We do this in a method called Game1.DrawPartsList as follows for int i 0 i charDef.Frames selFrame .Parts.Length i int y 5 i 15 text.Size 0.75f string line int index charDef.Frames selFrame .Parts i .Index if index 0 line CHAPTER 5 THE CHARACTER EDITOR 109 else if index 64 line head index.ToString else if index 74 line torso index.ToString else if index 128 line arms index.ToString else if index 192 line legs index.ToString else line weapon index.ToString if selPart i text.Color Color.Lime text.DrawText 600 y i.ToString line We ll put in two buttons to swap the current part with the one on the previous or next layer using a .