/// <summary> /// Position is the CENTER of the button /// </summary> public Button(Texture2D tex, Vector2 pos, buttonAction action, Screen screen) { this.tex = tex; this.pos = pos; this.action = action; screen.buttons.Add(this); Vector2 p = this.pos - new Vector2(this.tex.Width, this.tex.Height) * .5f; // translate up and left my 1/2 the size for hitbox this.rect = new Rectangle((int)p.X, (int)p.Y, this.tex.Width, this.tex.Height); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); MainPlayer.LoadContent(Content); Dust.dustTex = Content.Load<Texture2D>("dust"); groundtex = Content.Load<Texture2D>("Ground"); bgTreetex = Content.Load<Texture2D>("Tree/BGTree"); Texture2D play = Content.Load<Texture2D>("tap/btnPlay"); Texture2D youlose = Content.Load<Texture2D>("tap/lose"); Texture2D logo = Content.Load<Texture2D>("tap/logo"); Texture2D tapLeft = Content.Load<Texture2D>("tap/Left"); Texture2D tapRight = Content.Load<Texture2D>("tap/Right"); Screen main = new Screen(true, "main"); new Button(play, new Vector2(viewport.Width * .5f, viewport.Height * 0.75f), buttonAction.pregame, main); new Label(logo, new Vector2(viewport.Width * .5f, viewport.Height * 0.25f), main); Screen pregame = new Screen(false, "pregame"); new Label(tapLeft, new Vector2((viewport.Width * .5f) - (100), viewport.Height * 0.75f), pregame); new Label(tapRight, new Vector2((viewport.Width * .5f) + (100), viewport.Height * 0.75f), pregame); new Button(play, new Vector2(viewport.Width * .5f, viewport.Height * 0.75f), buttonAction.startgame, pregame); Screen lose = new Screen(false, "lose"); new Label(youlose, new Vector2(viewport.Width * .5f, viewport.Height * 0.25f), lose); new Button(play, new Vector2(viewport.Width * .5f, viewport.Height * 0.75f), buttonAction.startgame, lose); chop = Content.Load<SoundEffect>("chop"); }
public Label(Texture2D tex, Vector2 pos, Screen screen) { this.tex = tex; this.pos = pos; screen.labels.Add(this); }