tailieunhanh - Building XNA 2.0 Games- P5

Building XNA 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 i 4 80 i 4 64 80 if i 15 i 30 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 texture dRect sRect if if mouseClick selFrame .Parts selPart .Index i 64 l Assuming we add a call to DrawPalette and DrawCursor at the end of 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 as follows for int i 0 i selFrame . i int y 5 i 15 string line int index selFrame .Parts i .Index if index 0 line CHAPTER 5 THE CHARACTER EDITOR 109 else if index 64 line head else if index 74 line torso else if index 128 line arms else if index 192 line legs else line weapon if selPart i 600 y line We ll put in two buttons to swap the current part with the one on the previous or next layer using a .