private static Button GenerateButton(SpriteFont spriteFont, Texture2D buttonTexture, string buttonText, Vector2 buttonPosition) { var nextButtonTransform = new Transform2D(buttonPosition, Rectangle.Empty); var nextButtonText = new Text(buttonText, spriteFont, new Transform2D(Vector2.Zero, Rectangle.Empty)); var nextButton = new Button(buttonTexture, nextButtonText, nextButtonTransform); return nextButton; }
//public Button() //{ // this.Texture = null; // this.Text.Transform = new Transform2D(this.Transform); // this.Transform.Size = new Rectangle(0, 0, 100, 50); // this.Text.TextContent = "Button"; //} public Button( Texture2D texture, Text text, Transform2D transform, Transform2D parentTransform = null) { this.Texture = texture; this.Transform = transform; this.Transform.Size = new Rectangle(Point.Zero, new Point(this.Texture.Width / 2, this.Texture.Height / 2)); this.Transform.Parent = parentTransform; this.Text = text; this.Text.Transform.Parent = this.Transform; this.CenterTextInButton(); InputManager.OnPress += this.HandleButtonPress; InputManager.OnRelease += this.HandleButtonRelease; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { this.IsMouseVisible = true; DebugText = new Text("Debug", this.Content.Load<SpriteFont>("Fonts/impact")); DebugText.Transform.Parent = Repository.GetSelectedCamera().Transform; Repository.GameObjects.Add(DebugText); // Create a new SpriteBatch, which can be used to draw textures. this.spriteBatch = new SpriteBatch(this.GraphicsDevice); // TODO: use this.Content to load your game content here }