Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MenuButton : SpriteObject
- {
- //Menu buttons have a windows phone theme background, which is iteself a SpriteObject
- private static SpriteObject background;
- //Different Icons, static for loading
- private static Texture2D playButtonIcon;
- private static Texture2D highscoreButtonIcon;
- private static Texture2D settingButtonIcon;
- private static Texture2D aboutButtonIcon;
- private static Texture2D reviewButtonIcon;
- private static Texture2D brownsoftAppsIcon;
- private static Texture2D websiteIcon;
- //The tap countdown stops users from "pressing" a button constantly by holding their finger down in one place
- public static int TapCountdown = 0;
- //Constructor which forces size to be chosen and a button type
- public MenuButton(int requestedX, int requestedY, int requestedWidth, int requestedHeight, MenuButtonType requestedMenuButtonType)
- : base(requestedX, requestedY, requestedWidth, requestedHeight)
- {
- background = new SpriteObject(requestedX, requestedY, requestedWidth, requestedHeight);
- switch (requestedMenuButtonType)
- {
- case MenuButtonType.play:
- spriteTexture = playButtonIcon;
- break;
- case MenuButtonType.highscore:
- spriteTexture = highscoreButtonIcon;
- break;
- case MenuButtonType.settings:
- spriteTexture = settingButtonIcon;
- break;
- case MenuButtonType.about:
- spriteTexture = aboutButtonIcon;
- break;
- case MenuButtonType.review:
- spriteTexture = reviewButtonIcon;
- break;
- case MenuButtonType.brownsoftApps:
- spriteTexture = brownsoftAppsIcon;
- break;
- case MenuButtonType.website:
- spriteTexture = websiteIcon;
- break;
- }
- }
- //Method used to load all the private texture icons and transparent background
- public static void LoadContent(ContentManager Content)
- {
- //Windows Phone Theme Background
- background.spriteTexture = Content.Load<Texture2D>("Menu Items/Menu Buttons/WhiteBlank");
- //Main Menu Icons
- playButtonIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/PlayButtonIcon");
- highscoreButtonIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/HighscoreButtonIcon");
- settingButtonIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/SettingsButtonIcon");
- aboutButtonIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/AboutButtonIcon");
- //About Menu Icons
- brownsoftAppsIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/BrownsoftAppsButtonIcon");
- reviewButtonIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/ReviewButtonIcon");
- websiteIcon = Content.Load<Texture2D>("Menu Items/Menu Buttons/WebsiteButtonIcon");
- }
- //Method to detect if the button is currently being tapped
- public bool IsTapped(TouchCollection tc)
- {
- if (tc.Count == 0)
- {
- //If there are no fingers on the screen the button cannot be being touched, return false
- return false;
- }
- else
- {
- //There are fingers on the screen, check if any are touching the button
- //
- Rectangle fingerPosition;
- for (int i = 0; i < tc.Count; i++)
- {
- fingerPosition = new Rectangle((int)tc[i].Position.X, (int)tc[i].Position.Y, 1, 1);
- if(fingerPosition.Intersects(this.spriteRectagle) && TapCountdown == 0)
- {
- TapCountdown = 5;
- return true;
- }
- }
- return false;
- }
- }
- //Override the Draw method here because we need to draw both the background and the foreground Icon
- public override void Draw(SpriteBatch sb)
- {
- background.Draw(sb, WindowsPhoneTheme.getTileColour());
- base.Draw(sb);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement