@Idelgo wrote:
It's been a while since I've been trying to make it work as I want more for me it's complicated I'm not a programmer, I know almost nothing about C #, but it's almost like I want, however, when the mouse clicks on the event "Pressed" it executes very fast that I do not even see the texture of the button pressed;
Which could help me, as a very simple way to put a timer for the buttons, in a normal way where I see the button hovered, pressed and give the eventOBS: Sorry my english is bad
public class EngineButton { public string TextureName { get; set; } public Rectangle Rectangle { get; set; } private Texture2D[] Textures = new Texture2D[4]; private State state; private enum State { Released, Hovered, Pressed } public event EventHandler<EventArgs> Selected; protected internal virtual void OnSelectEntry() { Selected?.Invoke(this, EventArgs.Empty); } public EngineButton() { } public void LoadContent(ContentManager content) { Textures[1] = content.Load<Texture2D>("Textures/Buttons/" + TextureName + "_1"); Textures[2] = content.Load<Texture2D>("Textures/Buttons/" + TextureName + "_2"); Textures[3] = content.Load<Texture2D>("Textures/Buttons/" + TextureName + "_3"); Textures[0] = Textures[1]; } public void Update(MouseState mouseState) { if (Rectangle.Contains(mouseState.X, mouseState.Y)) { if (mouseState.LeftButton == ButtonState.Pressed) { state = State.Pressed; OnSelectEntry(); } else { state = state == State.Pressed ? State.Released : State.Hovered; } } else { state = State.Released; }; } public void Draw(SpriteBatch spriteBatch) { switch (state) { case State.Released: Textures[0] = Textures[1]; break; case State.Hovered: Textures[0] = Textures[2]; break; case State.Pressed: Textures[0] = Textures[3]; break; } spriteBatch.Draw(Textures[0], Rectangle, Color.White); } }
Posts: 1
Participants: 1