Repository navigation
Expand file tree
/
Copy pathButton.cs
More file actions
66 lines (60 loc) · 2.19 KB
/
Copy pathButton.cs
File metadata and controls
66 lines (60 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ActionGame
{
class Button:GraphicalGameObject
{
public event EventHandler Click;
public event EventHandler Hover;
public event EventHandler Leave;
SpriteFont font;
public TextObject text;
Texture2D def;
Texture2D hov;
Texture2D onC;
Point textL;
public Button(Game1 game, Point point) : base(game, game.assets.buttonD){
X = point.X;
Y = point.Y;
font = this.Content.Load<SpriteFont>("Font");
text = new TextObject(game, font, "button", Color.White);
def = game.assets.buttonD;
hov = game.assets.buttonH;
onC = game.assets.buttonC;
text.X = point.X;
text.Y = point.Y;
addAnimator(2);
}
public override void update(float delta)
{
var mouseState = Mouse.GetState();
var mousePosition = new Point(mouseState.X, mouseState.Y);
Rectangle area = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
if (game.input.onHover(area)) { game.assets.HoverSound.Play(); Texture = hov;if (Hover != null) Hover(this, EventArgs.Empty); }
if (game.input.onLeave(area)) Texture = def;
if (game.input.IsHover(area) && game.input.OnMouseDown(Input.LeftButton)) {
Texture = onC;
}
if (game.input.IsHover(area) && game.input.OnMouseUp(Input.LeftButton)) { game.assets.ClickSound.Play();if(Click!=null) Click(this, EventArgs.Empty); }
base.update(delta);
text.X =X+textL.X;
text.Y = Y+textL.Y;
}
public override void Draw(SpriteBatch batch, float screenAlpha)
{
base.Draw(batch, screenAlpha);
text.Draw(batch, screenAlpha);
}
public void setTextLocation(int tx,int ty)
{
textL = new Point(tx, ty);
}
}
}