tailieunhanh - programming windows phone 7 phần 9

Sau đó, bạn có thể vẽ trên RenderTarget2D này trong cùng một cách mà bạn vẽ trên bộ đệm trở lại. Sau khi bạn đã hoàn tất bản vẽ, bạn tách RenderTarget2D từ các GraphicsDevice với một cuộc gọi khác đến SetRenderTarget với một cuộc tranh luận vô giá trị: | You can then draw on this RenderTarget2D in the same way you draw on the back buffer. After you re finished drawing you disassociate the RenderTarget2D from the GraphicsDevice with another call to SetRenderTarget with a null argument null Now the GraphicsDevice is back to normal. If you re creating a RenderTarget2D that remains the same for the duration of the program you ll generally perform this entire operation during the LoadContent override. If the RenderTarget2D needs to change you can also draw on the bitmap during the Update override. Because RenderTarget2D derives from Texture2D you can display the RenderTarget2D on the screen during your Draw override just as you display any other Texture2D image. Of course you re not limited to one RenderTarget2D object. If you have a complex series of images that form some kind of animation you can create a series of RenderTarget2D objects that you then display in sequence as a kind of movie. Suppose you want to display something that looks like this That s a bunch of text strings all saying Windows Phone 7 rotated around a center point with colors that vary between cyan and yellow. Of course you can have a loop in the Draw override that makes 32 calls to the DrawString method of SpriteBatch but if you assemble those text strings on a single bitmap you can reduce the Draw override to just a single call to the Draw method of SpriteBatch. Moreover it becomes easier to treat this assemblage of text strings as a single entity and then perhaps rotate it like a pinwheel. That s the idea behind the PinwheelText program. The program s content includes the 14-point Segoe UI Mono SpriteFont but a SpriteFont object is not included among the program s fields nor is the text itself 801 XNA Project PinwheelText File excerpt showing fields public class Gamel GraphicsDeviceManager graphics SpriteBatch spriteBatch Vector2 screenCenter RenderTarget2D renderTarget .