Time for action – adding the UIHelper class
In order to add the static helper class, perform the following steps:
1. Add a new class file called
UIHelper.cs
to the Tank Battles project.2. Add the following
usi
ng
directives at the beginning of theUIHelper
class file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input;
3. Modify the declaration of the class to add the modifier
static
before it. The new class declaration should read:static class UIHelper
4. Add fields to the
UIHelper
class as follows:#region Fields public static Texture2D ButtonTexture; public static SpriteFont ButtonFont; #endregion
5. Add methods to the
UIHelper
class as follows:#region Helper Methods public static UIButton CreateButton( string id, string text, int x, int y) { UIButton b = new UIButton( id, new Vector2(x,y), new Vector2(25 - ButtonFont.MeasureString(text).X / 2, 10), ButtonFont, text, ...