WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0 in Office Word

Creator Data Matrix ECC200 in Office Word WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0

CHAPTER 3 WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0
Encoding Data Matrix ECC200 In None
Using Barcode generator for Microsoft Word Control to generate, create ECC200 image in Microsoft Word applications.
www.OnBarcode.com
Barcode Printer In None
Using Barcode encoder for Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
public MenuWindow(SpriteFont spriteFont) { itemList = new List<MenuItem>(); changeSpan = TimeSpan.FromMilliseconds(800); selectedItem = 0; changeProgress = 0; windowState = WindowState.Inactive; this.spriteFont = spriteFont; } You indicate that a transaction between two menus should be completed in 800 milliseconds, and a menu starts in Inactive mode. You can read all about the SpriteFont class and how to render text in the previous recipe. Next, you need a method that allows you to add items to the menu: public void AddMenuItem(string itemText, MenuWindow itemLink) { MenuItem newItem = new MenuItem(itemText, itemLink); itemList.Add(newItem); } The item s caption, as well as the menu that needs to be activated when the user selects the item, is passed in by the main program. A new MenuItem is created and added to the itemList. You also need a method that will activate an Inactive menu: public void WakeUp() { windowState = WindowState.Starting; } Like almost any component in an XNA application, this class will also need to be updated: public void Update(double timePassedSinceLastFrame) { if ((windowState == WindowState.Starting) || (windowState == WindowState.Ending)) changeProgress += timePassedSinceLastFrame / changeSpan.TotalMilliseconds; if (changeProgress >= 1.0f) { changeProgress = 0.0f; if (windowState == WindowState.Starting) windowState = WindowState.Active; else if (windowState == WindowState.Ending) windowState = WindowState.Inactive; } } This method will receive the number of milliseconds that have passed since the last update call (usually, this will be 1000/60 milliseconds; see recipe 1-5). If the menu is in transition
Code-39 Creator In None
Using Barcode creator for Microsoft Word Control to generate, create Code 39 image in Office Word applications.
www.OnBarcode.com
Code 128B Generator In None
Using Barcode maker for Office Word Control to generate, create Code128 image in Office Word applications.
www.OnBarcode.com
C HA PTER 3 WORKING WITH 2D IMA GES/TEXTU RES IN XN A 2.0
Making QR Code In None
Using Barcode generator for Office Word Control to generate, create Quick Response Code image in Word applications.
www.OnBarcode.com
Barcode Printer In None
Using Barcode printer for Office Word Control to generate, create Barcode image in Office Word applications.
www.OnBarcode.com
mode, the changeProgress variable is updated, so after the number of milliseconds stored in changeSpan (800, as you specified earlier), this value reaches 1. When this value reaches 1, the transition is over, and the state either has to be changed from Starting to Active or has to be changed from Ending to Inactive. Finally, you want some code that renders the menu. When the menu is Active, the items should be displayed, starting from, for example, position (300,300), with each item 30 pixels below the previous item. When the menu is in Starting mode, the items should fade in (their alpha value should increase from 0 to 1) and move from the left of the screen to their final position. When in Ending mode, the items should fade out (their alpha value should decrease), and they should move to the right. public void Draw(SpriteBatch spriteBatch) { if (windowState == WindowState.Inactive) return; float smoothedProgress = MathHelper.SmoothStep(0,1,(float)changeProgress); int verPosition = 300; float horPosition = 300; float alphaValue; switch (windowState) { case WindowState.Starting: horPosition -= 200 * (1.0f - (float)smoothedProgress); alphaValue = smoothedProgress; break; case WindowState.Ending: horPosition += 200 * (float)smoothedProgress; alphaValue = 1.0f - smoothedProgress; break; default: alphaValue = 1; break; } for (int itemID = 0; itemID < itemList.Count; itemID++) { Vector2 itemPostition = new Vector2(horPosition, verPosition); Color itemColor = Color.White; if (itemID == selectedItem) itemColor = new Color(new Vector4(1,0,0,alphaValue)); else itemColor = new Color(new Vector4(1,1,1,alphaValue));
Drawing Data Matrix In None
Using Barcode encoder for Word Control to generate, create Data Matrix image in Word applications.
www.OnBarcode.com
Code 2/5 Drawer In None
Using Barcode creation for Office Word Control to generate, create Industrial 2 of 5 image in Word applications.
www.OnBarcode.com
CHAPTER 3 WORKING WITH 2D IMAGES /TEXTURES IN XNA 2.0
Make Data Matrix In Java
Using Barcode generation for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
www.OnBarcode.com
DataMatrix Drawer In None
Using Barcode maker for Font Control to generate, create ECC200 image in Font applications.
www.OnBarcode.com
spriteBatch.DrawString(spriteFont, itemList[itemID].itemText, itemPostition, itemColor, 0, Vector2.Zero, 1, SpriteEffects.None, 0); verPosition += 30; } } When in Starting or Ending state, the changeProgress value will increase linearly from 0 to 1, which is OK but will not give smooth starts or endings. The MathHelper.SmoothStep method smoothens this curve, so the transitions will start and end smoothly. The case structure adjusts the horizontal position and alpha values for the menu items, in case the menu is in Starting or Ending mode. Next, for each item in the menu, the caption is rendered to the screen at the correct position. For more information on rendering text, see the previous recipe. If the item is not the selected item, its text is drawn in white, while the selected item will be drawn in red. That s it for the basics of the MenuWindow class! In your main program, you simply need a list to store all your menus: List<MenuWindow> menuList; In your LoadContent method, you can create your menus and add them to the menuList. Next, you can add items to the menus, allowing you to specify which menu should be activated next in case the user selects the item. MenuWindow menuMain = new MenuWindow(menuFont, "Main Menu", backgroundImage); MenuWindow menuNewGame = new MenuWindow(menuFont, "Start a New Game", bg); menuList.Add(menuMain); menuList.Add(menuNewGame); menuMain.AddMenuItem("New Game", menuNewGame); menuNewGame.AddMenuItem("Back to Main menu", menuMain); menuMain.WakeUp(); This will create two menus, each containing an item that links to the other menu. After you re done initializing your menu structure, the mainMenu is activated, bringing it in the Starting state. Now you need to update all your menus during the update cycle of your program: foreach (MenuWindow currentMenu in menuList) currentMenu.Update(gameTime.ElapsedGameTime.TotalMilliseconds); and render them during the draw phase of your program: spriteBatch.Begin(); foreach (MenuWindow currentMenu in menuList) currentMenu.Draw(spriteBatch); spriteBatch.End(); When you run this code, the main menu should come fading in from the left, but of course you can t yet move to the other menu because you aren t processing any user input yet.
Encode GS1 DataBar In VS .NET
Using Barcode maker for .NET Control to generate, create GS1 DataBar image in Visual Studio .NET applications.
www.OnBarcode.com
Code39 Encoder In Java
Using Barcode encoder for Java Control to generate, create Code-39 image in Java applications.
www.OnBarcode.com
Encode Universal Product Code Version A In Objective-C
Using Barcode printer for iPhone Control to generate, create UPC-A Supplement 2 image in iPhone applications.
www.OnBarcode.com
Drawing Barcode In Objective-C
Using Barcode drawer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Scanning ECC200 In VB.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
GTIN - 12 Reader In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
UCC - 12 Encoder In Java
Using Barcode maker for Java Control to generate, create GS1-128 image in Java applications.
www.OnBarcode.com
Code-128 Creator In None
Using Barcode creator for Font Control to generate, create Code-128 image in Font applications.
www.OnBarcode.com
Drawing Quick Response Code In Java
Using Barcode generation for Java Control to generate, create QR-Code image in Java applications.
www.OnBarcode.com
PDF-417 2d Barcode Creation In None
Using Barcode encoder for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.