ButtonGuide class

The ButtonGuide class is used to display a list of controller buttons and what they do. Each panel in the guide can be dynamically enabled and disabled to show only the commands currently available to the player.

This is useful with the XBox 360 Controller Button Images pack.

Constructors

public ButtonGuide(TextStyle textStyle, AnchorPoint anchor, int spacing, GraphicsDeviceManager graphics)
Creates a button guide with the defined TextStyle, anchored along the specified edge of the screen's title-safe area (TopLeft, TopRight, BottomLeft, or BottomRight), with the defined spacing in pixels.

public ButtonGuide(TextStyle textStyle, AnchorPoint anchor, int spacing, Vector2 position)
Creates a button guide with the defined TextStyle, anchored at a specified corner position, with the defined spacing in pixels.

Methods

public void AddPanel(string id, Texture2D icon, string text, bool visible)
Called when configuring the button guide.

public void Initialize()
Must be called immediately after adding panels to the button guide. Measures the dimensions of each panel in the button guide.

public void Draw(SpriteBatch spriteBatch)
Draws the button guide to the screen. Should be called within your game's Draw method.

Fields / Properties

public ButtonGuidePanelCollection Panels
Provides access to all panels within the guide. You can use this list to toggle the Visible attributes on each button guide to turn them off and on.

It's handy to use LINQ in this scenario:
(from p in guide.Panels where p.Id == "A" select p).First<ButtonGuide.ButtonGuidePanel>().Visible = true;

Example usage

public class Game1 : Microsoft.Xna.Framework.Game
{
	GraphicsDeviceManager graphics;
	SpriteBatch spriteBatch;
	ButtonGuide guide;

	public Game1()
	{
		graphics = new GraphicsDeviceManager(this);
		Content.RootDirectory = "Content";
	}

	protected override void LoadContent()
	{
		spriteBatch = new SpriteBatch(GraphicsDevice);

		TextStyle textStyle = new TextStyle(
			Content.Load<SpriteFont>("SpriteFont1"),
			Color.White, Color.Black, 1,
			TextStyle.Direction.BottomRight);

		guide = new ButtonGuide(textStyle, AnchorPoint.BottomRight, 8, graphics);
		guide.AddPanel("A", Content.Load<Texture2D>("xboxControllerButtonA"), "Button A", true);
		guide.AddPanel("B", Content.Load<Texture2D>("xboxControllerButtonB"), "Button B", true);
		guide.AddPanel("0", null, "No Icon", true);
		guide.AddPanel("X", Content.Load<Texture2D>("xboxControllerButtonX"), "Button X", true);
		guide.AddPanel("Y", Content.Load<Texture2D>("xboxControllerButtonY"), "Button Y", true);
		guide.Initialize();
        }

	protected override void Draw(GameTime gameTime)
	{
		GraphicsDevice.Clear(Color.CornflowerBlue);

		spriteBatch.Begin();
		guide.Draw(spriteBatch);
		spriteBatch.End();

		base.Draw(gameTime);
	}
}

Last edited Jan 4, 2010 at 3:44 AM by dylanwolf, version 2

Comments

No comments yet.