using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Input.Touch; namespace Graphics3DSample { /// /// A game component, inherits to Clickable. /// Has associated content. /// Has an integer Value that is incremented by click. /// Draws content. /// public class Button : Clickable { #region Fields readonly string asset; Texture2D texture; int value; #region Public accessors public int Value { get { return value; } } #endregion #endregion #region Initialization /// /// Constructor /// /// The Game object /// Texture Name /// Position of the component on the screen /// Initial value public Button (Graphics3DSampleGame game, string textureName, Rectangle targetRectangle, int initialValue) : base(game, targetRectangle) { asset = textureName; value = initialValue; } /// /// Load the button's texture /// protected override void LoadContent() { texture = Game.Content.Load(asset); base.LoadContent(); } #endregion #region Update and render /// /// Allows the game component to update itself /// /// Provides a snapshot of timing values. public override void Update(GameTime gameTime) { HandleInput(); if (IsClicked) ++value; base.Update(gameTime); } /// /// Allows the game component to update itself. /// /// Provides a snapshot of timing values. public override void Draw(GameTime gameTime) { var color = IsTouching ? Color.Wheat : Color.White; Game.SpriteBatch.Begin(); Game.SpriteBatch.Draw(texture, Rectangle, color); Game.SpriteBatch.End(); base.Draw(gameTime); } #endregion } }